From ef335d9fd736923fef0365cab7814be15eb338cd Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Mon, 6 Jul 2015 22:21:46 -0300 Subject: [PATCH] Add missing files --- testutil/testutil.go | 12 ++++++++++++ testutil/testutil_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 testutil/testutil.go create mode 100644 testutil/testutil_test.go diff --git a/testutil/testutil.go b/testutil/testutil.go new file mode 100644 index 000000000..71c3ce0c2 --- /dev/null +++ b/testutil/testutil.go @@ -0,0 +1,12 @@ +package testutil + +import "os" + +var localhost = "localhost" + +func GetLocalHost() string { + if dockerHostVar := os.Getenv("DOCKER_HOST"); dockerHostVar != "" { + return dockerHostVar + } + return localhost +} diff --git a/testutil/testutil_test.go b/testutil/testutil_test.go new file mode 100644 index 000000000..39f548c0f --- /dev/null +++ b/testutil/testutil_test.go @@ -0,0 +1,26 @@ +package testutil + +import ( + "os" + "testing" +) + +func TestDockerHost(t *testing.T) { + + os.Unsetenv("DOCKER_HOST") + + host := GetLocalHost() + + if host != localhost { + t.Fatalf("Host should be localhost when DOCKER_HOST is not set. Current value [%s]", host) + } + + os.Setenv("DOCKER_HOST", "1.1.1.1") + + 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")) + } + +}