hyper-v: add test for hashicorp/packer#5184
This commit is contained in:
parent
eeeee3ec35
commit
ae6987c74b
@ -6,7 +6,10 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
hypervcommon "github.com/hashicorp/packer/builder/hyperv/common"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
|
"github.com/mitchellh/multistep"
|
||||||
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func testConfig() map[string]interface{} {
|
func testConfig() map[string]interface{} {
|
||||||
@ -472,3 +475,45 @@ func TestBuilderPrepare_CommConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUserVariablesInBootCommand(t *testing.T) {
|
||||||
|
var b Builder
|
||||||
|
config := testConfig()
|
||||||
|
|
||||||
|
config[packer.UserVariablesConfigKey] = map[string]string{"test-variable": "test"}
|
||||||
|
config["boot_command"] = []string{"blah {{user `test-variable`}} blah"}
|
||||||
|
|
||||||
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not have error: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ui := packer.TestUi(t)
|
||||||
|
cache := &packer.FileCache{CacheDir: os.TempDir()}
|
||||||
|
hook := &packer.MockHook{}
|
||||||
|
driver := &hypervcommon.DriverMock{}
|
||||||
|
|
||||||
|
// Set up the state.
|
||||||
|
state := new(multistep.BasicStateBag)
|
||||||
|
state.Put("cache", cache)
|
||||||
|
state.Put("config", &b.config)
|
||||||
|
state.Put("driver", driver)
|
||||||
|
state.Put("hook", hook)
|
||||||
|
state.Put("http_port", uint(0))
|
||||||
|
state.Put("ui", ui)
|
||||||
|
state.Put("vmName", "packer-foo")
|
||||||
|
|
||||||
|
step := &hypervcommon.StepTypeBootCommand{
|
||||||
|
BootCommand: b.config.BootCommand,
|
||||||
|
SwitchName: b.config.SwitchName,
|
||||||
|
Ctx: b.config.ctx,
|
||||||
|
}
|
||||||
|
|
||||||
|
ret := step.Run(state)
|
||||||
|
if ret != multistep.ActionContinue {
|
||||||
|
t.Fatalf("should not have error: %s", ret)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user