diff --git a/builder/digitalocean/builder_test.go b/builder/digitalocean/builder_test.go index 9a0c3ed07..6fe9217dc 100644 --- a/builder/digitalocean/builder_test.go +++ b/builder/digitalocean/builder_test.go @@ -2,10 +2,17 @@ package digitalocean import ( "github.com/mitchellh/packer/packer" + "os" "strconv" "testing" ) +func init() { + // Clear out the credential env vars + os.Setenv("DIGITALOCEAN_API_KEY", "") + os.Setenv("DIGITALOCEAN_CLIENT_ID", "") +} + func testConfig() map[string]interface{} { return map[string]interface{}{ "client_id": "foo", @@ -55,6 +62,15 @@ func TestBuilderPrepare_APIKey(t *testing.T) { if err == nil { t.Fatal("should have error") } + + // Test env variable + delete(config, "api_key") + os.Setenv("DIGITALOCEAN_API_KEY", "foo") + defer os.Setenv("DIGITALOCEAN_API_KEY", "") + err = b.Prepare(config) + if err != nil { + t.Fatalf("should not have error: %s", err) + } } func TestBuilderPrepare_ClientID(t *testing.T) { @@ -79,6 +95,15 @@ func TestBuilderPrepare_ClientID(t *testing.T) { if err == nil { t.Fatal("should have error") } + + // Test env variable + delete(config, "client_id") + os.Setenv("DIGITALOCEAN_CLIENT_ID", "foo") + defer os.Setenv("DIGITALOCEAN_CLIENT_ID", "") + err = b.Prepare(config) + if err != nil { + t.Fatalf("should not have error: %s", err) + } } func TestBuilderPrepare_RegionID(t *testing.T) {