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