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"
|
|
|
|
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2016-04-14 20:29:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepCreateImageFromMachine(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepCreateImageFromMachine)
|
|
|
|
defer step.Cleanup(state)
|
|
|
|
|
|
|
|
state.Put("machine", "test-machine-id")
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, ok := state.GetOk("image")
|
|
|
|
if !ok {
|
|
|
|
t.Fatalf("should have image")
|
|
|
|
}
|
|
|
|
|
|
|
|
step.Cleanup(state)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepCreateImageFromMachine_CreateImageFromMachineError(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepCreateImageFromMachine)
|
|
|
|
defer step.Cleanup(state)
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
state.Put("machine", "test-machine-id")
|
|
|
|
|
|
|
|
driver.CreateImageFromMachineErr = 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")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := state.GetOk("image"); ok {
|
|
|
|
t.Fatalf("should NOT have image")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepCreateImageFromMachine_WaitForImageCreationError(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepCreateImageFromMachine)
|
|
|
|
defer step.Cleanup(state)
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
state.Put("machine", "test-machine-id")
|
|
|
|
|
|
|
|
driver.WaitForImageCreationErr = 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")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := state.GetOk("image"); ok {
|
|
|
|
t.Fatalf("should NOT have image")
|
|
|
|
}
|
|
|
|
}
|