github.phpd.cn/hashicorp/packer@v1.3.2/builder/virtualbox/common/vbox_version_config_test.go (about) 1 package common 2 3 import ( 4 "testing" 5 ) 6 7 func TestVBoxVersionConfigPrepare_BootWait(t *testing.T) { 8 var c *VBoxVersionConfig 9 var errs []error 10 11 // Test empty 12 c = new(VBoxVersionConfig) 13 errs = c.Prepare(testConfigTemplate(t)) 14 if len(errs) > 0 { 15 t.Fatalf("should not have error: %s", errs) 16 } 17 18 if *c.VBoxVersionFile != ".vbox_version" { 19 t.Fatalf("bad value: %s", *c.VBoxVersionFile) 20 } 21 22 // Test with a good one 23 c = new(VBoxVersionConfig) 24 filename := "foo" 25 c.VBoxVersionFile = &filename 26 errs = c.Prepare(testConfigTemplate(t)) 27 if len(errs) > 0 { 28 t.Fatalf("should not have error: %s", errs) 29 } 30 31 if *c.VBoxVersionFile != "foo" { 32 t.Fatalf("bad value: %s", *c.VBoxVersionFile) 33 } 34 } 35 36 func TestVBoxVersionConfigPrepare_empty(t *testing.T) { 37 var c *VBoxVersionConfig 38 var errs []error 39 40 // Test with nil value 41 c = new(VBoxVersionConfig) 42 c.VBoxVersionFile = nil 43 errs = c.Prepare(testConfigTemplate(t)) 44 if len(errs) > 0 { 45 t.Fatalf("should not have error: %s", errs) 46 } 47 48 if *c.VBoxVersionFile != ".vbox_version" { 49 t.Fatalf("bad value: %s", *c.VBoxVersionFile) 50 } 51 52 // Test with empty name 53 c = new(VBoxVersionConfig) 54 filename := "" 55 c.VBoxVersionFile = &filename 56 errs = c.Prepare(testConfigTemplate(t)) 57 if len(errs) > 0 { 58 t.Fatalf("should not have error: %s", errs) 59 } 60 61 if *c.VBoxVersionFile != "" { 62 t.Fatalf("bad value: %s", *c.VBoxVersionFile) 63 } 64 }