github.phpd.cn/hashicorp/packer@v1.3.2/builder/amazon/ebssurrogate/builder_test.go (about) 1 package ebssurrogate 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/packer/packer" 7 ) 8 9 func testConfig() map[string]interface{} { 10 return map[string]interface{}{ 11 "access_key": "foo", 12 "secret_key": "bar", 13 "source_ami": "foo", 14 "instance_type": "foo", 15 "region": "us-east-1", 16 "ssh_username": "root", 17 } 18 } 19 20 func TestBuilder_ImplementsBuilder(t *testing.T) { 21 var raw interface{} 22 raw = &Builder{} 23 if _, ok := raw.(packer.Builder); !ok { 24 t.Fatal("Builder should be a builder") 25 } 26 } 27 28 func TestBuilder_Prepare_BadType(t *testing.T) { 29 b := &Builder{} 30 c := map[string]interface{}{ 31 "access_key": []string{}, 32 } 33 34 warnings, err := b.Prepare(c) 35 if len(warnings) > 0 { 36 t.Fatalf("bad: %#v", warnings) 37 } 38 if err == nil { 39 t.Fatal("prepare should fail") 40 } 41 } 42 43 func TestBuilderPrepare_InvalidKey(t *testing.T) { 44 var b Builder 45 config := testConfig() 46 47 // Add a random key 48 config["i_should_not_be_valid"] = true 49 warnings, err := b.Prepare(config) 50 if len(warnings) > 0 { 51 t.Fatalf("bad: %#v", warnings) 52 } 53 if err == nil { 54 t.Fatal("should have error") 55 } 56 }