github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/virtualbox/ovf/step_import_test.go (about) 1 package ovf 2 3 import ( 4 vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common" 5 "github.com/mitchellh/multistep" 6 "testing" 7 ) 8 9 func TestStepImport_impl(t *testing.T) { 10 var _ multistep.Step = new(StepImport) 11 } 12 13 func TestStepImport(t *testing.T) { 14 state := testState(t) 15 state.Put("vm_path", "foo") 16 step := new(StepImport) 17 step.Name = "bar" 18 19 driver := state.Get("driver").(*vboxcommon.DriverMock) 20 21 // Test the run 22 if action := step.Run(state); action != multistep.ActionContinue { 23 t.Fatalf("bad action: %#v", action) 24 } 25 if _, ok := state.GetOk("error"); ok { 26 t.Fatal("should NOT have error") 27 } 28 29 // Test driver 30 if !driver.ImportCalled { 31 t.Fatal("import should be called") 32 } 33 if driver.ImportName != step.Name { 34 t.Fatalf("bad: %#v", driver.ImportName) 35 } 36 37 // Test output state 38 if name, ok := state.GetOk("vmName"); !ok { 39 t.Fatal("vmName should be set") 40 } else if name != "bar" { 41 t.Fatalf("bad: %#v", name) 42 } 43 44 // Test cleanup 45 step.Cleanup(state) 46 if !driver.DeleteCalled { 47 t.Fatal("delete should be called") 48 } 49 if driver.DeleteName != "bar" { 50 t.Fatalf("bad: %#v", driver.DeleteName) 51 } 52 }