mirror of https://github.com/hashicorp/packer
fix step_shutdown when a null communicator is used (#10178)
parent
8f3a115c5a
commit
fb3d357e84
@ -0,0 +1,88 @@
|
||||
package qemu
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/packer/helper/communicator"
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
func Test_Shutdown_Null_success(t *testing.T) {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packer.TestUi(t))
|
||||
driverMock := new(DriverMock)
|
||||
driverMock.WaitForShutdownState = true
|
||||
state.Put("driver", driverMock)
|
||||
|
||||
step := &stepShutdown{
|
||||
ShutdownCommand: "",
|
||||
ShutdownTimeout: 5 * time.Minute,
|
||||
Comm: &communicator.Config{
|
||||
Type: "none",
|
||||
},
|
||||
}
|
||||
action := step.Run(context.TODO(), state)
|
||||
if action != multistep.ActionContinue {
|
||||
t.Fatalf("Should have successfully shut down.")
|
||||
}
|
||||
err := state.Get("error")
|
||||
if err != nil {
|
||||
err = err.(error)
|
||||
t.Fatalf("Shutdown shouldn't have errored; err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Shutdown_Null_failure(t *testing.T) {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packer.TestUi(t))
|
||||
driverMock := new(DriverMock)
|
||||
driverMock.WaitForShutdownState = false
|
||||
state.Put("driver", driverMock)
|
||||
|
||||
step := &stepShutdown{
|
||||
ShutdownCommand: "",
|
||||
ShutdownTimeout: 5 * time.Minute,
|
||||
Comm: &communicator.Config{
|
||||
Type: "none",
|
||||
},
|
||||
}
|
||||
action := step.Run(context.TODO(), state)
|
||||
if action != multistep.ActionHalt {
|
||||
t.Fatalf("Shouldn't have successfully shut down.")
|
||||
}
|
||||
err := state.Get("error")
|
||||
if err == nil {
|
||||
t.Fatalf("Shutdown should have errored")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Shutdown_NoShutdownCommand(t *testing.T) {
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("ui", packer.TestUi(t))
|
||||
driverMock := new(DriverMock)
|
||||
state.Put("driver", driverMock)
|
||||
|
||||
step := &stepShutdown{
|
||||
ShutdownCommand: "",
|
||||
ShutdownTimeout: 5 * time.Minute,
|
||||
Comm: &communicator.Config{
|
||||
Type: "ssh",
|
||||
},
|
||||
}
|
||||
action := step.Run(context.TODO(), state)
|
||||
if action != multistep.ActionContinue {
|
||||
t.Fatalf("Should have successfully shut down.")
|
||||
}
|
||||
|
||||
if !driverMock.StopCalled {
|
||||
t.Fatalf("should have called Stop through the driver.")
|
||||
}
|
||||
err := state.Get("error")
|
||||
if err != nil {
|
||||
err = err.(error)
|
||||
t.Fatalf("Shutdown shouldn't have errored; err: %v", err)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue