From 5a6bcdeb7899c6518a60aba700308dbf7b92a587 Mon Sep 17 00:00:00 2001 From: Rickard von Essen Date: Wed, 12 Aug 2015 01:34:08 +0200 Subject: [PATCH] Fix interpolation of {{.Flavor}} in parallels_tools_guest_path. Fixes [GH-2543] --- .../step_upload_parallels_tools_test.go | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 builder/parallels/common/step_upload_parallels_tools_test.go diff --git a/builder/parallels/common/step_upload_parallels_tools_test.go b/builder/parallels/common/step_upload_parallels_tools_test.go new file mode 100644 index 000000000..0599912a9 --- /dev/null +++ b/builder/parallels/common/step_upload_parallels_tools_test.go @@ -0,0 +1,86 @@ +package common + +import ( + "github.com/mitchellh/multistep" + "github.com/mitchellh/packer/packer" + "testing" +) + +func TestStepUploadParallelsTools_impl(t *testing.T) { + var _ multistep.Step = new(StepUploadParallelsTools) +} + +func TestStepUploadParallelsTools(t *testing.T) { + state := testState(t) + state.Put("parallels_tools_path", "./step_upload_parallels_tools_test.go") + step := new(StepUploadParallelsTools) + step.ParallelsToolsMode = "upload" + step.ParallelsToolsGuestPath = "/tmp/prl-lin.iso" + step.ParallelsToolsFlavor = "lin" + + comm := new(packer.MockCommunicator) + state.Put("communicator", comm) + + // 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") + } + + // Verify + if comm.UploadPath != "/tmp/prl-lin.iso" { + t.Fatalf("bad: %#v", comm.UploadPath) + } +} + +func TestStepUploadParallelsTools_interpolate(t *testing.T) { + state := testState(t) + state.Put("parallels_tools_path", "./step_upload_parallels_tools_test.go") + step := new(StepUploadParallelsTools) + step.ParallelsToolsMode = "upload" + step.ParallelsToolsGuestPath = "/tmp/prl-{{ .Flavor }}.iso" + step.ParallelsToolsFlavor = "win" + + comm := new(packer.MockCommunicator) + state.Put("communicator", comm) + + // 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") + } + + // Verify + if comm.UploadPath != "/tmp/prl-win.iso" { + t.Fatalf("bad: %#v", comm.UploadPath) + } +} + +func TestStepUploadParallelsTools_attach(t *testing.T) { + state := testState(t) + state.Put("parallels_tools_path", "./step_upload_parallels_tools_test.go") + step := new(StepUploadParallelsTools) + step.ParallelsToolsMode = "attach" + step.ParallelsToolsGuestPath = "/tmp/prl-lin.iso" + step.ParallelsToolsFlavor = "lin" + + comm := new(packer.MockCommunicator) + state.Put("communicator", comm) + + // 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") + } + + // Verify + if comm.UploadCalled { + t.Fatal("bad") + } +}