2013-12-22 18:19:19 -05:00
|
|
|
package ovf
|
|
|
|
|
|
|
|
import (
|
2018-01-22 19:03:49 -05:00
|
|
|
"context"
|
2018-01-22 20:21:10 -05:00
|
|
|
"testing"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common"
|
2020-11-17 19:31:03 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep"
|
2013-12-22 18:19:19 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepImport_impl(t *testing.T) {
|
|
|
|
var _ multistep.Step = new(StepImport)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepImport(t *testing.T) {
|
|
|
|
state := testState(t)
|
2016-10-10 22:16:25 -04:00
|
|
|
state.Put("vm_path", "foo")
|
2019-12-20 05:50:18 -05:00
|
|
|
|
2013-12-22 18:19:19 -05:00
|
|
|
step := new(StepImport)
|
|
|
|
step.Name = "bar"
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*vboxcommon.DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2013-12-22 18:19:19 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test driver
|
|
|
|
if !driver.ImportCalled {
|
|
|
|
t.Fatal("import should be called")
|
|
|
|
}
|
|
|
|
if driver.ImportName != step.Name {
|
|
|
|
t.Fatalf("bad: %#v", driver.ImportName)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test output state
|
|
|
|
if name, ok := state.GetOk("vmName"); !ok {
|
|
|
|
t.Fatal("vmName should be set")
|
|
|
|
} else if name != "bar" {
|
|
|
|
t.Fatalf("bad: %#v", name)
|
|
|
|
}
|
2019-12-19 07:30:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepImport_Cleanup(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
state.Put("vm_path", "foo")
|
|
|
|
|
|
|
|
step := new(StepImport)
|
|
|
|
step.vmName = "bar"
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*vboxcommon.DriverMock)
|
2013-12-22 18:19:19 -05:00
|
|
|
|
2019-12-20 05:50:18 -05:00
|
|
|
step.KeepRegistered = true
|
2017-09-13 09:37:26 -04:00
|
|
|
step.Cleanup(state)
|
|
|
|
if driver.DeleteCalled {
|
|
|
|
t.Fatal("delete should not be called")
|
|
|
|
}
|
|
|
|
|
2019-12-19 07:30:54 -05:00
|
|
|
state.Put(multistep.StateHalted, true)
|
2013-12-22 18:19:19 -05:00
|
|
|
step.Cleanup(state)
|
|
|
|
if !driver.DeleteCalled {
|
|
|
|
t.Fatal("delete should be called")
|
|
|
|
}
|
|
|
|
if driver.DeleteName != "bar" {
|
|
|
|
t.Fatalf("bad: %#v", driver.DeleteName)
|
|
|
|
}
|
|
|
|
}
|