diff --git a/builder/vmware/iso/step_suppress_messages.go b/builder/vmware/common/step_suppress_messages.go similarity index 65% rename from builder/vmware/iso/step_suppress_messages.go rename to builder/vmware/common/step_suppress_messages.go index e2044fdcd..a02b69336 100644 --- a/builder/vmware/iso/step_suppress_messages.go +++ b/builder/vmware/common/step_suppress_messages.go @@ -1,18 +1,17 @@ -package iso +package common import ( "fmt" "github.com/mitchellh/multistep" - vmwcommon "github.com/mitchellh/packer/builder/vmware/common" "github.com/mitchellh/packer/packer" "log" ) // This step suppresses any messages that VMware product might show. -type stepSuppressMessages struct{} +type StepSuppressMessages struct{} -func (s *stepSuppressMessages) Run(state multistep.StateBag) multistep.StepAction { - driver := state.Get("driver").(vmwcommon.Driver) +func (s *StepSuppressMessages) Run(state multistep.StateBag) multistep.StepAction { + driver := state.Get("driver").(Driver) ui := state.Get("ui").(packer.Ui) vmxPath := state.Get("vmx_path").(string) @@ -27,4 +26,4 @@ func (s *stepSuppressMessages) Run(state multistep.StateBag) multistep.StepActio return multistep.ActionContinue } -func (s *stepSuppressMessages) Cleanup(state multistep.StateBag) {} +func (s *StepSuppressMessages) Cleanup(state multistep.StateBag) {} diff --git a/builder/vmware/common/step_suppress_messages_test.go b/builder/vmware/common/step_suppress_messages_test.go new file mode 100644 index 000000000..998cfdb24 --- /dev/null +++ b/builder/vmware/common/step_suppress_messages_test.go @@ -0,0 +1,36 @@ +package common + +import ( + "testing" + + "github.com/mitchellh/multistep" +) + +func TestStepSuppressMessages_impl(t *testing.T) { + var _ multistep.Step = new(StepSuppressMessages) +} + +func TestStepSuppressMessages(t *testing.T) { + state := testState(t) + step := new(StepSuppressMessages) + + state.Put("vmx_path", "foo") + + driver := state.Get("driver").(*DriverMock) + + // Test the run + if action := step.Run(state); action != multistep.ActionContinue { + t.Fatalf("bad action: %#v", action) + } + if _, ok := state.GetOk("error"); ok { + t.Fatal("should NOT have error") + } + + // Test the driver + if !driver.SuppressMessagesCalled { + t.Fatal("should've called") + } + if driver.SuppressMessagesPath != "foo" { + t.Fatal("should call with right path") + } +} diff --git a/builder/vmware/common/step_test.go b/builder/vmware/common/step_test.go index 27c37495e..9bf6d5d67 100644 --- a/builder/vmware/common/step_test.go +++ b/builder/vmware/common/step_test.go @@ -9,6 +9,7 @@ import ( func testState(t *testing.T) multistep.StateBag { state := new(multistep.BasicStateBag) + state.Put("driver", new(DriverMock)) state.Put("ui", &packer.BasicUi{ Reader: new(bytes.Buffer), Writer: new(bytes.Buffer), diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index ea19bf24a..351a8de51 100644 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -392,7 +392,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe &vmwcommon.StepConfigureVMX{ CustomData: b.config.VMXData, }, - &stepSuppressMessages{}, + &vmwcommon.StepSuppressMessages{}, &stepHTTPServer{}, &stepConfigureVNC{}, &stepRun{},