github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/triton/step_create_source_machine_test.go (about) 1 package triton 2 3 import ( 4 "errors" 5 "testing" 6 7 "github.com/mitchellh/multistep" 8 ) 9 10 func TestStepCreateSourceMachine(t *testing.T) { 11 state := testState(t) 12 step := new(StepCreateSourceMachine) 13 defer step.Cleanup(state) 14 15 driver := state.Get("driver").(*DriverMock) 16 17 if action := step.Run(state); action != multistep.ActionContinue { 18 t.Fatalf("bad action: %#v", action) 19 } 20 21 machineIdRaw, ok := state.GetOk("machine") 22 if !ok { 23 t.Fatalf("should have machine") 24 } 25 26 step.Cleanup(state) 27 28 if driver.DeleteMachineId != machineIdRaw.(string) { 29 t.Fatalf("should've deleted machine (%s != %s)", driver.DeleteMachineId, machineIdRaw.(string)) 30 } 31 } 32 33 func TestStepCreateSourceMachine_CreateMachineError(t *testing.T) { 34 state := testState(t) 35 step := new(StepCreateSourceMachine) 36 defer step.Cleanup(state) 37 38 driver := state.Get("driver").(*DriverMock) 39 40 driver.CreateMachineErr = errors.New("error") 41 42 if action := step.Run(state); action != multistep.ActionHalt { 43 t.Fatalf("bad action: %#v", action) 44 } 45 46 if _, ok := state.GetOk("error"); !ok { 47 t.Fatalf("should have error") 48 } 49 50 if _, ok := state.GetOk("machine"); ok { 51 t.Fatalf("should NOT have machine") 52 } 53 } 54 55 func TestStepCreateSourceMachine_WaitForMachineStateError(t *testing.T) { 56 state := testState(t) 57 step := new(StepCreateSourceMachine) 58 defer step.Cleanup(state) 59 60 driver := state.Get("driver").(*DriverMock) 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 72 if _, ok := state.GetOk("machine"); ok { 73 t.Fatalf("should NOT have machine") 74 } 75 } 76 77 func TestStepCreateSourceMachine_StopMachineError(t *testing.T) { 78 state := testState(t) 79 step := new(StepCreateSourceMachine) 80 defer step.Cleanup(state) 81 82 driver := state.Get("driver").(*DriverMock) 83 84 if action := step.Run(state); action != multistep.ActionContinue { 85 t.Fatalf("bad action: %#v", action) 86 } 87 88 _, ok := state.GetOk("machine") 89 if !ok { 90 t.Fatalf("should have machine") 91 } 92 93 driver.StopMachineErr = errors.New("error") 94 step.Cleanup(state) 95 96 if _, ok := state.GetOk("error"); !ok { 97 t.Fatalf("should have error") 98 } 99 100 if _, ok := state.GetOk("machine"); !ok { 101 t.Fatalf("should have machine") 102 } 103 } 104 105 func TestStepCreateSourceMachine_WaitForMachineStoppedError(t *testing.T) { 106 state := testState(t) 107 step := new(StepCreateSourceMachine) 108 defer step.Cleanup(state) 109 110 driver := state.Get("driver").(*DriverMock) 111 112 if action := step.Run(state); action != multistep.ActionContinue { 113 t.Fatalf("bad action: %#v", action) 114 } 115 116 _, ok := state.GetOk("machine") 117 if !ok { 118 t.Fatalf("should have machine") 119 } 120 121 driver.WaitForMachineStateErr = errors.New("error") 122 step.Cleanup(state) 123 124 if _, ok := state.GetOk("error"); !ok { 125 t.Fatalf("should have error") 126 } 127 128 if _, ok := state.GetOk("machine"); !ok { 129 t.Fatalf("should have machine") 130 } 131 } 132 133 func TestStepCreateSourceMachine_DeleteMachineError(t *testing.T) { 134 state := testState(t) 135 step := new(StepCreateSourceMachine) 136 defer step.Cleanup(state) 137 138 driver := state.Get("driver").(*DriverMock) 139 140 if action := step.Run(state); action != multistep.ActionContinue { 141 t.Fatalf("bad action: %#v", action) 142 } 143 144 _, ok := state.GetOk("machine") 145 if !ok { 146 t.Fatalf("should have machine") 147 } 148 149 driver.DeleteMachineErr = errors.New("error") 150 step.Cleanup(state) 151 152 if _, ok := state.GetOk("error"); !ok { 153 t.Fatalf("should have error") 154 } 155 156 if _, ok := state.GetOk("machine"); !ok { 157 t.Fatalf("should have machine") 158 } 159 }