github.com/phobos182/packer@v0.2.3-0.20130819023704-c84d2aeffc68/builder/amazon/chroot/builder_test.go (about) 1 package chroot 2 3 import ( 4 "github.com/mitchellh/packer/packer" 5 "testing" 6 ) 7 8 func testConfig() map[string]interface{} { 9 return map[string]interface{}{ 10 "ami_name": "foo", 11 "source_ami": "foo", 12 } 13 } 14 15 func TestBuilder_ImplementsBuilder(t *testing.T) { 16 var raw interface{} 17 raw = &Builder{} 18 if _, ok := raw.(packer.Builder); !ok { 19 t.Fatalf("Builder should be a builder") 20 } 21 } 22 23 func TestBuilderPrepare_AMIName(t *testing.T) { 24 var b Builder 25 config := testConfig() 26 27 // Test good 28 config["ami_name"] = "foo" 29 err := b.Prepare(config) 30 if err != nil { 31 t.Fatalf("should not have error: %s", err) 32 } 33 34 // Test bad 35 config["ami_name"] = "foo {{" 36 b = Builder{} 37 err = b.Prepare(config) 38 if err == nil { 39 t.Fatal("should have error") 40 } 41 42 // Test bad 43 delete(config, "ami_name") 44 b = Builder{} 45 err = b.Prepare(config) 46 if err == nil { 47 t.Fatal("should have error") 48 } 49 } 50 51 func TestBuilderPrepare_ChrootMounts(t *testing.T) { 52 b := &Builder{} 53 config := testConfig() 54 55 config["chroot_mounts"] = nil 56 err := b.Prepare(config) 57 if err != nil { 58 t.Errorf("err: %s", err) 59 } 60 61 config["chroot_mounts"] = [][]string{ 62 []string{"bad"}, 63 } 64 err = b.Prepare(config) 65 if err == nil { 66 t.Fatal("should have error") 67 } 68 } 69 func TestBuilderPrepare_SourceAmi(t *testing.T) { 70 b := &Builder{} 71 config := testConfig() 72 73 config["source_ami"] = "" 74 err := b.Prepare(config) 75 if err == nil { 76 t.Fatal("should have error") 77 } 78 79 config["source_ami"] = "foo" 80 err = b.Prepare(config) 81 if err != nil { 82 t.Errorf("err: %s", err) 83 } 84 }