Commit 490279c6 authored by Jack Pearkes's avatar Jack Pearkes

builder/digitalocean: add tests for credentials via env vars

parent d701adb3
...@@ -2,10 +2,17 @@ package digitalocean ...@@ -2,10 +2,17 @@ package digitalocean
import ( import (
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"os"
"strconv" "strconv"
"testing" "testing"
) )
func init() {
// Clear out the credential env vars
os.Setenv("DIGITALOCEAN_API_KEY", "")
os.Setenv("DIGITALOCEAN_CLIENT_ID", "")
}
func testConfig() map[string]interface{} { func testConfig() map[string]interface{} {
return map[string]interface{}{ return map[string]interface{}{
"client_id": "foo", "client_id": "foo",
...@@ -55,6 +62,15 @@ func TestBuilderPrepare_APIKey(t *testing.T) { ...@@ -55,6 +62,15 @@ func TestBuilderPrepare_APIKey(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("should have error") 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) { func TestBuilderPrepare_ClientID(t *testing.T) {
...@@ -79,6 +95,15 @@ func TestBuilderPrepare_ClientID(t *testing.T) { ...@@ -79,6 +95,15 @@ func TestBuilderPrepare_ClientID(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("should have error") 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) { func TestBuilderPrepare_RegionID(t *testing.T) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment