github.com/raghuse92/packer@v1.3.2/common/bootcommand/config_test.go (about) 1 package bootcommand 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/packer/template/interpolate" 7 ) 8 9 func TestConfigPrepare(t *testing.T) { 10 var c *BootConfig 11 12 // Test a default boot_wait 13 c = new(BootConfig) 14 c.RawBootWait = "" 15 errs := c.Prepare(&interpolate.Context{}) 16 if len(errs) > 0 { 17 t.Fatalf("bad: %#v", errs) 18 } 19 if c.RawBootWait != "10s" { 20 t.Fatalf("bad value: %s", c.RawBootWait) 21 } 22 23 // Test with a bad boot_wait 24 c = new(BootConfig) 25 c.RawBootWait = "this is not good" 26 errs = c.Prepare(&interpolate.Context{}) 27 if len(errs) == 0 { 28 t.Fatal("should error") 29 } 30 31 // Test with a good one 32 c = new(BootConfig) 33 c.RawBootWait = "5s" 34 errs = c.Prepare(&interpolate.Context{}) 35 if len(errs) > 0 { 36 t.Fatalf("bad: %#v", errs) 37 } 38 } 39 40 func TestVNCConfigPrepare(t *testing.T) { 41 var c *VNCConfig 42 43 // Test with a boot command 44 c = new(VNCConfig) 45 c.BootCommand = []string{"a", "b"} 46 errs := c.Prepare(&interpolate.Context{}) 47 if len(errs) > 0 { 48 t.Fatalf("bad: %#v", errs) 49 } 50 51 // Test with disabled vnc 52 c.DisableVNC = true 53 errs = c.Prepare(&interpolate.Context{}) 54 if len(errs) == 0 { 55 t.Fatal("should error") 56 } 57 58 // Test no boot command with no vnc 59 c = new(VNCConfig) 60 c.DisableVNC = true 61 errs = c.Prepare(&interpolate.Context{}) 62 if len(errs) > 0 { 63 t.Fatalf("bad: %#v", errs) 64 } 65 }