2017-01-31 05:05:49 -05:00
|
|
|
package common
|
2013-12-24 16:39:52 -05:00
|
|
|
|
|
|
|
import (
|
2018-01-22 19:03:49 -05:00
|
|
|
"context"
|
2013-12-24 16:39:52 -05:00
|
|
|
"testing"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2018-01-22 18:32:33 -05:00
|
|
|
"github.com/hashicorp/packer/helper/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
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2013-12-24 16:39:52 -05:00
|
|
|
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)
|
2018-11-02 18:44:27 -04:00
|
|
|
step := &StepRegister{
|
|
|
|
KeepRegistered: false,
|
|
|
|
SkipExport: true,
|
|
|
|
}
|
2013-12-24 16:39:52 -05:00
|
|
|
|
|
|
|
driver := new(RemoteDriverMock)
|
2016-03-16 18:17:35 -04:00
|
|
|
|
2013-12-24 16:39:52 -05:00
|
|
|
state.Put("driver", driver)
|
|
|
|
state.Put("vmx_path", "foo")
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2013-12-24 16:39:52 -05:00
|
|
|
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)
|
2017-02-06 02:13:37 -05:00
|
|
|
step := &StepRegister{KeepRegistered: true}
|
2016-03-16 18:17:35 -04:00
|
|
|
|
|
|
|
driver := new(RemoteDriverMock)
|
|
|
|
|
|
|
|
state.Put("driver", driver)
|
|
|
|
state.Put("vmx_path", "foo")
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2016-03-16 18:17:35 -04:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|