From 7bd37b1f7a4e765dd40d89f6947c0e88a8c2bd69 Mon Sep 17 00:00:00 2001 From: Travis Truman Date: Tue, 14 Apr 2015 11:14:58 -0400 Subject: [PATCH] Tests were failing incorrectly when OpenStack environment variables were set in the environment running the tests --- builder/openstack/access_config_test.go | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/builder/openstack/access_config_test.go b/builder/openstack/access_config_test.go index 5c92216e3..cf37448cc 100644 --- a/builder/openstack/access_config_test.go +++ b/builder/openstack/access_config_test.go @@ -1,9 +1,17 @@ package openstack import ( + "os" "testing" ) +func init() { + // Clear out the openstack env vars so they don't + // affect our tests. + os.Setenv("SDK_REGION", "") + os.Setenv("OS_REGION_NAME", "") +} + func testAccessConfig() *AccessConfig { return &AccessConfig{} } @@ -16,6 +24,38 @@ func TestAccessConfigPrepare_NoRegion_Rackspace(t *testing.T) { } } +func TestAccessConfigRegionWithEmptyEnv(t *testing.T) { + c := testAccessConfig() + c.Prepare(nil) + if c.Region() != "" { + t.Fatalf("Region should be empty") + } +} + +func TestAccessConfigRegionWithSdkRegionEnv(t *testing.T) { + c := testAccessConfig() + c.Prepare(nil) + + expectedRegion := "sdk_region" + os.Setenv("SDK_REGION", expectedRegion) + os.Setenv("OS_REGION_NAME", "") + if c.Region() != expectedRegion { + t.Fatalf("Region should be: %s", expectedRegion) + } +} + +func TestAccessConfigRegionWithOsRegionNameEnv(t *testing.T) { + c := testAccessConfig() + c.Prepare(nil) + + expectedRegion := "os_region_name" + os.Setenv("SDK_REGION", "") + os.Setenv("OS_REGION_NAME", expectedRegion) + if c.Region() != expectedRegion { + t.Fatalf("Region should be: %s", expectedRegion) + } +} + func TestAccessConfigPrepare_NoRegion_PrivateCloud(t *testing.T) { c := testAccessConfig() c.Provider = "http://some-keystone-server:5000/v2.0"