github.phpd.cn/hashicorp/packer@v1.3.2/builder/oneandone/builder_test.go (about) 1 package oneandone 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/hashicorp/packer/packer" 8 ) 9 10 func testConfig() map[string]interface{} { 11 return map[string]interface{}{ 12 "type": "oneandone", 13 "disk_size": "50", 14 "snapshot_name": "test5", 15 "image": "ubuntu1604-64min", 16 } 17 } 18 19 func TestImplementsBuilder(t *testing.T) { 20 var raw interface{} 21 raw = &Builder{} 22 if _, ok := raw.(packer.Builder); !ok { 23 t.Fatalf("Builder should be a builder") 24 } 25 } 26 27 func TestBuilder_Prepare_BadType(t *testing.T) { 28 b := &Builder{} 29 c := map[string]interface{}{ 30 "api_key": []string{}, 31 } 32 33 warns, err := b.Prepare(c) 34 if len(warns) > 0 { 35 t.Fatalf("bad: %#v", warns) 36 } 37 if err == nil { 38 fmt.Println(err) 39 fmt.Println(warns) 40 t.Fatalf("prepare should fail") 41 } 42 } 43 44 func TestBuilderPrepare_InvalidKey(t *testing.T) { 45 var b Builder 46 config := testConfig() 47 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 }