2013-12-24 20:12:43 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
2013-12-24 20:12:43 -05:00
|
|
|
"testing"
|
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2013-12-24 20:12:43 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepRun_impl(t *testing.T) {
|
|
|
|
var _ multistep.Step = new(StepRun)
|
|
|
|
}
|
|
|
|
|
2018-01-22 19:03:49 -05:00
|
|
|
func TestStepRun(t *testing.T) {
|
2013-12-24 20:12:43 -05:00
|
|
|
state := testState(t)
|
|
|
|
step := new(StepRun)
|
|
|
|
|
|
|
|
state.Put("vmx_path", "foo")
|
|
|
|
|
|
|
|
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 {
|
2013-12-24 20:12:43 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the driver
|
|
|
|
if !driver.StartCalled {
|
|
|
|
t.Fatal("start should be called")
|
|
|
|
}
|
|
|
|
if driver.StartPath != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", driver.StartPath)
|
|
|
|
}
|
|
|
|
if driver.StartHeadless {
|
|
|
|
t.Fatal("bad")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test cleanup
|
|
|
|
step.Cleanup(state)
|
|
|
|
if driver.StopCalled {
|
|
|
|
t.Fatal("stop should not be called if not running")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepRun_cleanupRunning(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepRun)
|
|
|
|
|
|
|
|
state.Put("vmx_path", "foo")
|
|
|
|
|
|
|
|
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 {
|
2013-12-24 20:12:43 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the driver
|
|
|
|
if !driver.StartCalled {
|
|
|
|
t.Fatal("start should be called")
|
|
|
|
}
|
|
|
|
if driver.StartPath != "foo" {
|
|
|
|
t.Fatalf("bad: %#v", driver.StartPath)
|
|
|
|
}
|
|
|
|
if driver.StartHeadless {
|
|
|
|
t.Fatal("bad")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark that it is running
|
|
|
|
driver.IsRunningResult = true
|
|
|
|
|
|
|
|
// Test cleanup
|
|
|
|
step.Cleanup(state)
|
|
|
|
if !driver.StopCalled {
|
|
|
|
t.Fatal("stop should be called")
|
|
|
|
}
|
|
|
|
}
|