Files
Packer-Cn/builder/triton/step_create_image_from_machine_test.go
T

75 lines
1.7 KiB
Go
Raw Normal View History

2016-04-14 17:29:27 -07:00
package triton
import (
2018-01-22 16:03:49 -08:00
"context"
2016-04-14 17:29:27 -07:00
"errors"
"testing"
2018-01-19 16:18:44 -08:00
"github.com/hashicorp/packer/helper/multistep"
2016-04-14 17:29:27 -07: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 16:03:49 -08:00
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
2016-04-14 17:29:27 -07: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 16:03:49 -08:00
if action := step.Run(context.Background(), state); action != multistep.ActionHalt {
2016-04-14 17:29:27 -07: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 16:03:49 -08:00
if action := step.Run(context.Background(), state); action != multistep.ActionHalt {
2016-04-14 17:29:27 -07: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")
}
}