github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/triton/step_stop_machine_test.go (about) 1 package triton 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/mitchellh/multistep" 8 ) 9 10 func TestStepStopMachine(t *testing.T) { 11 state := testState(t) 12 step := new(StepStopMachine) 13 defer step.Cleanup(state) 14 15 driver := state.Get("driver").(*DriverMock) 16 17 machineId := "test-machine-id" 18 state.Put("machine", machineId) 19 20 if action := step.Run(state); action != multistep.ActionContinue { 21 t.Fatalf("bad action: %#v", action) 22 } 23 24 step.Cleanup(state) 25 26 if driver.StopMachineId != machineId { 27 t.Fatalf("should've stopped machine (%s != %s)", driver.StopMachineId, machineId) 28 } 29 } 30 31 func TestStepStopMachine_StopMachineError(t *testing.T) { 32 state := testState(t) 33 step := new(StepStopMachine) 34 defer step.Cleanup(state) 35 36 driver := state.Get("driver").(*DriverMock) 37 38 machineId := "test-machine-id" 39 state.Put("machine", machineId) 40 41 driver.StopMachineErr = errors.New("error") 42 43 if action := step.Run(state); action != multistep.ActionHalt { 44 t.Fatalf("bad action: %#v", action) 45 } 46 47 if _, ok := state.GetOk("error"); !ok { 48 t.Fatalf("should have error") 49 } 50 } 51 52 func TestStepStopMachine_WaitForMachineStoppedError(t *testing.T) { 53 state := testState(t) 54 step := new(StepStopMachine) 55 defer step.Cleanup(state) 56 57 driver := state.Get("driver").(*DriverMock) 58 59 machineId := "test-machine-id" 60 state.Put("machine", machineId) 61 62 driver.WaitForMachineStateErr = errors.New("error") 63 64 if action := step.Run(state); action != multistep.ActionHalt { 65 t.Fatalf("bad action: %#v", action) 66 } 67 68 if _, ok := state.GetOk("error"); !ok { 69 t.Fatalf("should have error") 70 } 71 }