Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetLocalHost testutil function for mac users (boot2docker) #85

Merged
merged 1 commit into from
Aug 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions testutil/testutil.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
package testutil

import "os"
import (
"net"
"net/url"
"os"
)

var localhost = "localhost"

func GetLocalHost() string {
if dockerHostVar := os.Getenv("DOCKER_HOST"); dockerHostVar != "" {
return dockerHostVar
u, err := url.Parse(dockerHostVar)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs indentation.

if err != nil {
return dockerHostVar
}

// split out the ip addr from the port
host, _, err := net.SplitHostPort(u.Host)
if err != nil {
return dockerHostVar
}

return host
}
return localhost
}
8 changes: 8 additions & 0 deletions testutil/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,12 @@ func TestDockerHost(t *testing.T) {
t.Fatalf("Host should take DOCKER_HOST value when set. Current value is [%s] and DOCKER_HOST is [%s]", host, os.Getenv("DOCKER_HOST"))
}

os.Setenv("DOCKER_HOST", "tcp://1.1.1.1:8080")

host = GetLocalHost()

if host != "1.1.1.1" {
t.Fatalf("Host should take DOCKER_HOST value when set. Current value is [%s] and DOCKER_HOST is [%s]", host, os.Getenv("DOCKER_HOST"))
}

}