|
|
|
|
@ -2,9 +2,19 @@ package amazonebs
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
|
"os"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
// Clear out the AWS access key env vars so they don't
|
|
|
|
|
// affect our tests.
|
|
|
|
|
os.Setenv("AWS_ACCESS_KEY_ID", "")
|
|
|
|
|
os.Setenv("AWS_ACCESS_KEY", "")
|
|
|
|
|
os.Setenv("AWS_SECRET_ACCESS_KEY", "")
|
|
|
|
|
os.Setenv("AWS_SECRET_KEY", "")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testConfig() map[string]interface{} {
|
|
|
|
|
return map[string]interface{}{
|
|
|
|
|
"access_key": "foo",
|
|
|
|
|
@ -59,6 +69,31 @@ func TestBuilderPrepare_AccessKey(t *testing.T) {
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test env
|
|
|
|
|
delete(config, "access_key")
|
|
|
|
|
os.Setenv("AWS_ACCESS_KEY_ID", "foo")
|
|
|
|
|
defer os.Setenv("AWS_ACCESS_KEY_ID", "")
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if b.config.AccessKey != "foo" {
|
|
|
|
|
t.Errorf("access key invalid: %s", b.config.AccessKey)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete(config, "access_key")
|
|
|
|
|
os.Setenv("AWS_ACCESS_KEY", "foo")
|
|
|
|
|
defer os.Setenv("AWS_ACCESS_KEY", "")
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if b.config.AccessKey != "foo" {
|
|
|
|
|
t.Errorf("access key invalid: %s", b.config.AccessKey)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBuilderPrepare_AMIName(t *testing.T) {
|
|
|
|
|
@ -167,6 +202,31 @@ func TestBuilderPrepare_SecretKey(t *testing.T) {
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatal("should have error")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test env
|
|
|
|
|
delete(config, "secret_key")
|
|
|
|
|
os.Setenv("AWS_SECRET_ACCESS_KEY", "foo")
|
|
|
|
|
defer os.Setenv("AWS_SECRET_ACCESS_KEY", "")
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if b.config.SecretKey != "foo" {
|
|
|
|
|
t.Errorf("access key invalid: %s", b.config.SecretKey)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete(config, "secret_key")
|
|
|
|
|
os.Setenv("AWS_SECRET_KEY", "foo")
|
|
|
|
|
defer os.Setenv("AWS_SECRET_KEY", "")
|
|
|
|
|
err = b.Prepare(config)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if b.config.SecretKey != "foo" {
|
|
|
|
|
t.Errorf("access key invalid: %s", b.config.SecretKey)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBuilderPrepare_SourceAmi(t *testing.T) {
|
|
|
|
|
|