github.phpd.cn/hashicorp/packer@v1.3.2/builder/profitbricks/builder_test.go (about) 1 package profitbricks 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 "image": "Ubuntu-16.04", 13 "password": "password", 14 "username": "username", 15 "snapshot_name": "packer", 16 "type": "profitbricks", 17 } 18 } 19 20 func TestImplementsBuilder(t *testing.T) { 21 var raw interface{} 22 raw = &Builder{} 23 if _, ok := raw.(packer.Builder); !ok { 24 t.Fatalf("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 "api_key": []string{}, 32 } 33 34 warns, err := b.Prepare(c) 35 if len(warns) > 0 { 36 t.Fatalf("bad: %#v", warns) 37 } 38 if err == nil { 39 fmt.Println(err) 40 fmt.Println(warns) 41 t.Fatalf("prepare should fail") 42 } 43 } 44 45 func TestBuilderPrepare_InvalidKey(t *testing.T) { 46 var b Builder 47 config := testConfig() 48 49 config["i_should_not_be_valid"] = true 50 warnings, err := b.Prepare(config) 51 if len(warnings) > 0 { 52 t.Fatalf("bad: %#v", warnings) 53 } 54 if err == nil { 55 t.Fatal("should have error") 56 } 57 }