2014-09-02 04:42:12 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 19:03:49 -05:00
|
|
|
"context"
|
2014-09-02 04:42:12 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2014-09-02 04:42:12 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepPrepareParallelsTools_impl(t *testing.T) {
|
|
|
|
var _ multistep.Step = new(StepPrepareParallelsTools)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepPrepareParallelsTools(t *testing.T) {
|
|
|
|
tf, err := ioutil.TempFile("", "packer")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
tf.Close()
|
|
|
|
defer os.Remove(tf.Name())
|
|
|
|
|
|
|
|
state := testState(t)
|
|
|
|
step := &StepPrepareParallelsTools{
|
|
|
|
ParallelsToolsMode: "",
|
|
|
|
ParallelsToolsFlavor: "foo",
|
|
|
|
}
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Mock results
|
2016-12-11 13:49:54 -05:00
|
|
|
driver.ToolsISOPathResult = tf.Name()
|
2014-09-02 04:42:12 -04:00
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2014-09-02 04:42:12 -04:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the driver
|
2016-12-11 13:49:54 -05:00
|
|
|
if !driver.ToolsISOPathCalled {
|
2014-09-02 04:42:12 -04:00
|
|
|
t.Fatal("tools iso path should be called")
|
|
|
|
}
|
2016-12-11 13:49:54 -05:00
|
|
|
if driver.ToolsISOPathFlavor != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", driver.ToolsISOPathFlavor)
|
2014-09-02 04:42:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the resulting state
|
|
|
|
path, ok := state.GetOk("parallels_tools_path")
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("should have parallels_tools_path")
|
|
|
|
}
|
|
|
|
if path != tf.Name() {
|
|
|
|
t.Fatalf("bad: %#v", path)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepPrepareParallelsTools_disabled(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := &StepPrepareParallelsTools{
|
|
|
|
ParallelsToolsFlavor: "foo",
|
|
|
|
ParallelsToolsMode: ParallelsToolsModeDisable,
|
|
|
|
}
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2014-09-02 04:42:12 -04:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the driver
|
2016-12-11 13:49:54 -05:00
|
|
|
if driver.ToolsISOPathCalled {
|
|
|
|
t.Fatal("tools ISO path should NOT be called")
|
2014-09-02 04:42:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepPrepareParallelsTools_nonExist(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := &StepPrepareParallelsTools{
|
|
|
|
ParallelsToolsFlavor: "foo",
|
|
|
|
ParallelsToolsMode: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Mock results
|
2016-12-11 13:49:54 -05:00
|
|
|
driver.ToolsISOPathResult = "foo"
|
2014-09-02 04:42:12 -04:00
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionHalt {
|
2014-09-02 04:42:12 -04:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); !ok {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the driver
|
2016-12-11 13:49:54 -05:00
|
|
|
if !driver.ToolsISOPathCalled {
|
2014-09-02 04:42:12 -04:00
|
|
|
t.Fatal("tools iso path should be called")
|
|
|
|
}
|
2016-12-11 13:49:54 -05:00
|
|
|
if driver.ToolsISOPathFlavor != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", driver.ToolsISOPathFlavor)
|
2014-09-02 04:42:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Test the resulting state
|
|
|
|
if _, ok := state.GetOk("parallels_tools_path"); ok {
|
|
|
|
t.Fatal("should NOT have parallels_tools_path")
|
|
|
|
}
|
|
|
|
}
|