github.phpd.cn/hashicorp/packer@v1.3.2/builder/vmware/common/step_run_test.go (about) 1 package common 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/hashicorp/packer/helper/multistep" 8 ) 9 10 func TestStepRun_impl(t *testing.T) { 11 var _ multistep.Step = new(StepRun) 12 } 13 14 func TestStepRun(t *testing.T) { 15 state := testState(t) 16 step := new(StepRun) 17 18 state.Put("vmx_path", "foo") 19 20 driver := state.Get("driver").(*DriverMock) 21 22 // Test the run 23 if action := step.Run(context.Background(), state); action != multistep.ActionContinue { 24 t.Fatalf("bad action: %#v", action) 25 } 26 if _, ok := state.GetOk("error"); ok { 27 t.Fatal("should NOT have error") 28 } 29 30 // Test the driver 31 if !driver.StartCalled { 32 t.Fatal("start should be called") 33 } 34 if driver.StartPath != "foo" { 35 t.Fatalf("bad: %#v", driver.StartPath) 36 } 37 if driver.StartHeadless { 38 t.Fatal("bad") 39 } 40 41 // Test cleanup 42 step.Cleanup(state) 43 if driver.StopCalled { 44 t.Fatal("stop should not be called if not running") 45 } 46 } 47 48 func TestStepRun_cleanupRunning(t *testing.T) { 49 state := testState(t) 50 step := new(StepRun) 51 52 state.Put("vmx_path", "foo") 53 54 driver := state.Get("driver").(*DriverMock) 55 56 // Test the run 57 if action := step.Run(context.Background(), state); action != multistep.ActionContinue { 58 t.Fatalf("bad action: %#v", action) 59 } 60 if _, ok := state.GetOk("error"); ok { 61 t.Fatal("should NOT have error") 62 } 63 64 // Test the driver 65 if !driver.StartCalled { 66 t.Fatal("start should be called") 67 } 68 if driver.StartPath != "foo" { 69 t.Fatalf("bad: %#v", driver.StartPath) 70 } 71 if driver.StartHeadless { 72 t.Fatal("bad") 73 } 74 75 // Mark that it is running 76 driver.IsRunningResult = true 77 78 // Test cleanup 79 step.Cleanup(state) 80 if !driver.StopCalled { 81 t.Fatal("stop should be called") 82 } 83 }