2016-04-14 20:29:27 -04:00
|
|
|
package triton
|
|
|
|
|
|
|
|
import (
|
2018-01-22 19:03:49 -05:00
|
|
|
"context"
|
2016-04-14 20:29:27 -04:00
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2016-04-14 20:29:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepStopMachine(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepStopMachine)
|
|
|
|
defer step.Cleanup(state)
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
machineId := "test-machine-id"
|
|
|
|
state.Put("machine", machineId)
|
|
|
|
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2016-04-14 20:29:27 -04:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
|
|
|
|
step.Cleanup(state)
|
|
|
|
|
|
|
|
if driver.StopMachineId != machineId {
|
|
|
|
t.Fatalf("should've stopped machine (%s != %s)", driver.StopMachineId, machineId)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepStopMachine_StopMachineError(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepStopMachine)
|
|
|
|
defer step.Cleanup(state)
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
machineId := "test-machine-id"
|
|
|
|
state.Put("machine", machineId)
|
|
|
|
|
|
|
|
driver.StopMachineErr = errors.New("error")
|
|
|
|
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionHalt {
|
2016-04-14 20:29:27 -04:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := state.GetOk("error"); !ok {
|
|
|
|
t.Fatalf("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepStopMachine_WaitForMachineStoppedError(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepStopMachine)
|
|
|
|
defer step.Cleanup(state)
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
machineId := "test-machine-id"
|
|
|
|
state.Put("machine", machineId)
|
|
|
|
|
|
|
|
driver.WaitForMachineStateErr = errors.New("error")
|
|
|
|
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionHalt {
|
2016-04-14 20:29:27 -04:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := state.GetOk("error"); !ok {
|
|
|
|
t.Fatalf("should have error")
|
|
|
|
}
|
|
|
|
}
|