github.com/kaixiang/packer@v0.5.2-0.20140114230416-1f5786b0d7f1/builder/vmware/iso/step_register_test.go (about) 1 package iso 2 3 import ( 4 "github.com/mitchellh/multistep" 5 "testing" 6 ) 7 8 func TestStepRegister_impl(t *testing.T) { 9 var _ multistep.Step = new(StepRegister) 10 } 11 12 func TestStepRegister_regularDriver(t *testing.T) { 13 state := testState(t) 14 step := new(StepRegister) 15 16 state.Put("vmx_path", "foo") 17 18 // Test the run 19 if action := step.Run(state); action != multistep.ActionContinue { 20 t.Fatalf("bad action: %#v", action) 21 } 22 if _, ok := state.GetOk("error"); ok { 23 t.Fatal("should NOT have error") 24 } 25 26 // Cleanup 27 step.Cleanup(state) 28 } 29 30 func TestStepRegister_remoteDriver(t *testing.T) { 31 state := testState(t) 32 step := new(StepRegister) 33 34 driver := new(RemoteDriverMock) 35 state.Put("driver", driver) 36 state.Put("vmx_path", "foo") 37 38 // Test the run 39 if action := step.Run(state); action != multistep.ActionContinue { 40 t.Fatalf("bad action: %#v", action) 41 } 42 if _, ok := state.GetOk("error"); ok { 43 t.Fatal("should NOT have error") 44 } 45 46 // verify 47 if !driver.RegisterCalled { 48 t.Fatal("register should be called") 49 } 50 if driver.RegisterPath != "foo" { 51 t.Fatal("should call with correct path") 52 } 53 if driver.UnregisterCalled { 54 t.Fatal("unregister should not be called") 55 } 56 57 // cleanup 58 step.Cleanup(state) 59 if !driver.UnregisterCalled { 60 t.Fatal("unregister should be called") 61 } 62 if driver.UnregisterPath != "foo" { 63 t.Fatal("should unregister proper path") 64 } 65 }