packer-cn/builder/triton/step_stop_machine_test.go

73 lines
1.6 KiB
Go
Raw Normal View History

package triton
import (
2018-01-22 19:03:49 -05:00
"context"
"errors"
"testing"
2020-12-17 16:29:25 -05:00
"github.com/hashicorp/packer-plugin-sdk/multistep"
)
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 {
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 {
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 {
t.Fatalf("bad action: %#v", action)
}
if _, ok := state.GetOk("error"); !ok {
t.Fatalf("should have error")
}
}