github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/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 var config Config 36 config.KeepRegistered = false 37 state.Put("config", &config) 38 39 state.Put("driver", driver) 40 state.Put("vmx_path", "foo") 41 42 // Test the run 43 if action := step.Run(state); action != multistep.ActionContinue { 44 t.Fatalf("bad action: %#v", action) 45 } 46 if _, ok := state.GetOk("error"); ok { 47 t.Fatal("should NOT have error") 48 } 49 50 // verify 51 if !driver.RegisterCalled { 52 t.Fatal("register should be called") 53 } 54 if driver.RegisterPath != "foo" { 55 t.Fatal("should call with correct path") 56 } 57 if driver.UnregisterCalled { 58 t.Fatal("unregister should not be called") 59 } 60 61 // cleanup 62 step.Cleanup(state) 63 if !driver.UnregisterCalled { 64 t.Fatal("unregister should be called") 65 } 66 if driver.UnregisterPath != "foo" { 67 t.Fatal("should unregister proper path") 68 } 69 } 70 func TestStepRegister_WithoutUnregister_remoteDriver(t *testing.T) { 71 state := testState(t) 72 step := new(StepRegister) 73 74 driver := new(RemoteDriverMock) 75 var config Config 76 config.KeepRegistered = true 77 state.Put("config", &config) 78 79 state.Put("driver", driver) 80 state.Put("vmx_path", "foo") 81 82 // Test the run 83 if action := step.Run(state); action != multistep.ActionContinue { 84 t.Fatalf("bad action: %#v", action) 85 } 86 if _, ok := state.GetOk("error"); ok { 87 t.Fatal("should NOT have error") 88 } 89 90 // cleanup 91 step.Cleanup(state) 92 if driver.UnregisterCalled { 93 t.Fatal("unregister should not be called") 94 } 95 }