packer-cn/builder/triton/step_create_image_from_mach...

75 lines
1.7 KiB
Go
Raw Normal View History

package triton
import (
2018-01-22 19:03:49 -05:00
"context"
"errors"
"testing"
"github.com/hashicorp/packer/helper/multistep"
)
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 {
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 {
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 {
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")
}
}