github.com/sneal/packer@v0.5.2/builder/virtualbox/ovf/step_import_test.go (about) 1 package ovf 2 3 import ( 4 "github.com/mitchellh/multistep" 5 vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common" 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 step := new(StepImport) 16 step.Name = "bar" 17 step.SourcePath = "foo" 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 if driver.ImportPath != step.SourcePath { 37 t.Fatalf("bad: %#v", driver.ImportPath) 38 } 39 40 // Test output state 41 if name, ok := state.GetOk("vmName"); !ok { 42 t.Fatal("vmName should be set") 43 } else if name != "bar" { 44 t.Fatalf("bad: %#v", name) 45 } 46 47 // Test cleanup 48 step.Cleanup(state) 49 if !driver.DeleteCalled { 50 t.Fatal("delete should be called") 51 } 52 if driver.DeleteName != "bar" { 53 t.Fatalf("bad: %#v", driver.DeleteName) 54 } 55 }