packer-cn/builder/hyperv/common/step_set_boot_order_test.go

49 lines
1.1 KiB
Go
Raw Normal View History

package common
import (
"context"
"reflect"
"testing"
2020-12-17 16:29:25 -05:00
"github.com/hashicorp/packer-plugin-sdk/multistep"
)
type bootOrderTest struct {
bootOrder []string
}
var bootOrderTests = [...]bootOrderTest{
{[]string{"SCSI:0:0"}},
}
func TestStepSetBootOrder(t *testing.T) {
step := new(StepSetBootOrder)
for _, d := range bootOrderTests {
state := testState(t)
driver := state.Get("driver").(*DriverMock)
vmName := "test"
state.Put("vmName", vmName)
step.BootOrder = d.bootOrder
action := step.Run(context.Background(), state)
if multistep.ActionContinue != action {
t.Fatalf("Should have returned action %v but got %v", multistep.ActionContinue, action)
}
if vmName != driver.SetBootOrder_VmName {
t.Fatalf("Should have set VmName to %v but got %v", vmName, driver.SetBootOrder_VmName)
}
if !driver.SetBootOrder_Called {
t.Fatalf("Should have called SetBootOrder")
}
if !reflect.DeepEqual(d.bootOrder, driver.SetBootOrder_BootOrder) {
t.Fatalf("Should have set BootOrder to %v but got %v", d.bootOrder, driver.SetBootOrder_BootOrder)
}
}
}