github.com/sneal/packer@v0.5.2/builder/vmware/common/shutdown_config_test.go (about) 1 package common 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func testShutdownConfig() *ShutdownConfig { 9 return &ShutdownConfig{} 10 } 11 12 func TestShutdownConfigPrepare_ShutdownCommand(t *testing.T) { 13 var c *ShutdownConfig 14 var errs []error 15 16 c = testShutdownConfig() 17 errs = c.Prepare(testConfigTemplate(t)) 18 if len(errs) > 0 { 19 t.Fatalf("err: %#v", errs) 20 } 21 } 22 23 func TestShutdownConfigPrepare_ShutdownTimeout(t *testing.T) { 24 var c *ShutdownConfig 25 var errs []error 26 27 // Test with a bad value 28 c = testShutdownConfig() 29 c.RawShutdownTimeout = "this is not good" 30 errs = c.Prepare(testConfigTemplate(t)) 31 if len(errs) == 0 { 32 t.Fatalf("should have error") 33 } 34 35 // Test with a good one 36 c = testShutdownConfig() 37 c.RawShutdownTimeout = "5s" 38 errs = c.Prepare(testConfigTemplate(t)) 39 if len(errs) > 0 { 40 t.Fatalf("err: %#v", errs) 41 } 42 if c.ShutdownTimeout != 5*time.Second { 43 t.Fatalf("bad: %s", c.ShutdownTimeout) 44 } 45 }