2013-12-24 16:39:52 -05:00
|
|
|
package iso
|
|
|
|
|
|
|
|
import (
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2013-12-24 16:39:52 -05:00
|
|
|
"testing"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
|
|
|
"github.com/mitchellh/multistep"
|
2013-12-24 16:39:52 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepRegister_impl(t *testing.T) {
|
|
|
|
var _ multistep.Step = new(StepRegister)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepRegister_regularDriver(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepRegister)
|
|
|
|
|
|
|
|
state.Put("vmx_path", "foo")
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
step.Cleanup(state)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepRegister_remoteDriver(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepRegister)
|
|
|
|
|
|
|
|
driver := new(RemoteDriverMock)
|
2016-03-16 18:17:35 -04:00
|
|
|
var config Config
|
|
|
|
config.KeepRegistered = false
|
|
|
|
state.Put("config", &config)
|
|
|
|
|
2013-12-24 16:39:52 -05:00
|
|
|
state.Put("driver", driver)
|
|
|
|
state.Put("vmx_path", "foo")
|
|
|
|
|
|
|
|
// 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 !driver.RegisterCalled {
|
|
|
|
t.Fatal("register should be called")
|
|
|
|
}
|
|
|
|
if driver.RegisterPath != "foo" {
|
|
|
|
t.Fatal("should call with correct path")
|
|
|
|
}
|
|
|
|
if driver.UnregisterCalled {
|
|
|
|
t.Fatal("unregister should not be called")
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
step.Cleanup(state)
|
|
|
|
if !driver.UnregisterCalled {
|
|
|
|
t.Fatal("unregister should be called")
|
|
|
|
}
|
|
|
|
if driver.UnregisterPath != "foo" {
|
|
|
|
t.Fatal("should unregister proper path")
|
|
|
|
}
|
|
|
|
}
|
2016-03-16 18:17:35 -04:00
|
|
|
func TestStepRegister_WithoutUnregister_remoteDriver(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepRegister)
|
|
|
|
|
|
|
|
driver := new(RemoteDriverMock)
|
|
|
|
var config Config
|
2016-04-22 13:44:54 -04:00
|
|
|
config.KeepRegistered = true
|
2016-03-16 18:17:35 -04:00
|
|
|
state.Put("config", &config)
|
|
|
|
|
|
|
|
state.Put("driver", driver)
|
|
|
|
state.Put("vmx_path", "foo")
|
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
step.Cleanup(state)
|
|
|
|
if driver.UnregisterCalled {
|
|
|
|
t.Fatal("unregister should not be called")
|
|
|
|
}
|
|
|
|
}
|