github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/triton/step_delete_machine_test.go (about) 1 package triton 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/mitchellh/multistep" 8 ) 9 10 func TestStepDeleteMachine(t *testing.T) { 11 state := testState(t) 12 step := new(StepDeleteMachine) 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.DeleteMachineId != machineId { 27 t.Fatalf("should've deleted machine (%s != %s)", driver.DeleteMachineId, machineId) 28 } 29 } 30 31 func TestStepDeleteMachine_DeleteMachineError(t *testing.T) { 32 state := testState(t) 33 step := new(StepDeleteMachine) 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.DeleteMachineErr = 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 if _, ok := state.GetOk("machine"); !ok { 52 t.Fatalf("should have machine") 53 } 54 } 55 56 func TestStepDeleteMachine_WaitForMachineDeletionError(t *testing.T) { 57 state := testState(t) 58 step := new(StepDeleteMachine) 59 defer step.Cleanup(state) 60 61 driver := state.Get("driver").(*DriverMock) 62 63 machineId := "test-machine-id" 64 state.Put("machine", machineId) 65 66 driver.WaitForMachineDeletionErr = errors.New("error") 67 68 if action := step.Run(state); action != multistep.ActionHalt { 69 t.Fatalf("bad action: %#v", action) 70 } 71 72 if _, ok := state.GetOk("error"); !ok { 73 t.Fatalf("should have error") 74 } 75 76 if _, ok := state.GetOk("machine"); !ok { 77 t.Fatalf("should have machine") 78 } 79 }