github.phpd.cn/hashicorp/packer@v1.3.2/builder/triton/step_delete_machine_test.go (about) 1 package triton 2 3 import ( 4 "context" 5 "errors" 6 "testing" 7 8 "github.com/hashicorp/packer/helper/multistep" 9 ) 10 11 func TestStepDeleteMachine(t *testing.T) { 12 state := testState(t) 13 step := new(StepDeleteMachine) 14 defer step.Cleanup(state) 15 16 driver := state.Get("driver").(*DriverMock) 17 18 machineId := "test-machine-id" 19 state.Put("machine", machineId) 20 21 if action := step.Run(context.Background(), state); action != multistep.ActionContinue { 22 t.Fatalf("bad action: %#v", action) 23 } 24 25 step.Cleanup(state) 26 27 if driver.DeleteMachineId != machineId { 28 t.Fatalf("should've deleted machine (%s != %s)", driver.DeleteMachineId, machineId) 29 } 30 } 31 32 func TestStepDeleteMachine_DeleteMachineError(t *testing.T) { 33 state := testState(t) 34 step := new(StepDeleteMachine) 35 defer step.Cleanup(state) 36 37 driver := state.Get("driver").(*DriverMock) 38 39 machineId := "test-machine-id" 40 state.Put("machine", machineId) 41 42 driver.DeleteMachineErr = errors.New("error") 43 44 if action := step.Run(context.Background(), state); action != multistep.ActionHalt { 45 t.Fatalf("bad action: %#v", action) 46 } 47 48 if _, ok := state.GetOk("error"); !ok { 49 t.Fatalf("should have error") 50 } 51 52 if _, ok := state.GetOk("machine"); !ok { 53 t.Fatalf("should have machine") 54 } 55 } 56 57 func TestStepDeleteMachine_WaitForMachineDeletionError(t *testing.T) { 58 state := testState(t) 59 step := new(StepDeleteMachine) 60 defer step.Cleanup(state) 61 62 driver := state.Get("driver").(*DriverMock) 63 64 machineId := "test-machine-id" 65 state.Put("machine", machineId) 66 67 driver.WaitForMachineDeletionErr = errors.New("error") 68 69 if action := step.Run(context.Background(), state); action != multistep.ActionHalt { 70 t.Fatalf("bad action: %#v", action) 71 } 72 73 if _, ok := state.GetOk("error"); !ok { 74 t.Fatalf("should have error") 75 } 76 77 if _, ok := state.GetOk("machine"); !ok { 78 t.Fatalf("should have machine") 79 } 80 }