builder/qemu: passing tests
This commit is contained in:
parent
77b7169bd5
commit
3683d7cd23
@ -92,15 +92,15 @@ type config struct {
|
|||||||
tpl *packer.ConfigTemplate
|
tpl *packer.ConfigTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) Prepare(raws ...interface{}) error {
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
md, err := common.DecodeConfig(&b.config, raws...)
|
md, err := common.DecodeConfig(&b.config, raws...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.config.tpl, err = packer.NewConfigTemplate()
|
b.config.tpl, err = packer.NewConfigTemplate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
b.config.tpl.UserVars = b.config.PackerUserVars
|
b.config.tpl.UserVars = b.config.PackerUserVars
|
||||||
|
|
||||||
@ -361,10 +361,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if errs != nil && len(errs.Errors) > 0 {
|
if errs != nil && len(errs.Errors) > 0 {
|
||||||
return errs
|
return nil, errs
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
||||||
|
@ -59,7 +59,10 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
|
|||||||
func TestBuilderPrepare_Defaults(t *testing.T) {
|
func TestBuilderPrepare_Defaults(t *testing.T) {
|
||||||
var b Builder
|
var b Builder
|
||||||
config := testConfig()
|
config := testConfig()
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -95,7 +98,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
|
|||||||
|
|
||||||
// Test a default boot_wait
|
// Test a default boot_wait
|
||||||
delete(config, "boot_wait")
|
delete(config, "boot_wait")
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
@ -106,7 +112,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
|
|||||||
|
|
||||||
// Test with a bad boot_wait
|
// Test with a bad boot_wait
|
||||||
config["boot_wait"] = "this is not good"
|
config["boot_wait"] = "this is not good"
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -114,7 +123,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
|
|||||||
// Test with a good one
|
// Test with a good one
|
||||||
config["boot_wait"] = "5s"
|
config["boot_wait"] = "5s"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -125,7 +137,10 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
|
|||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
||||||
delete(config, "disk_size")
|
delete(config, "disk_size")
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("bad err: %s", err)
|
t.Fatalf("bad err: %s", err)
|
||||||
}
|
}
|
||||||
@ -136,7 +151,10 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
|
|||||||
|
|
||||||
config["disk_size"] = 60000
|
config["disk_size"] = 60000
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -151,7 +169,10 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
|
|||||||
config := testConfig()
|
config := testConfig()
|
||||||
|
|
||||||
delete(config, "floppy_files")
|
delete(config, "floppy_files")
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("bad err: %s", err)
|
t.Fatalf("bad err: %s", err)
|
||||||
}
|
}
|
||||||
@ -162,7 +183,10 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
|
|||||||
|
|
||||||
config["floppy_files"] = []string{"foo", "bar"}
|
config["floppy_files"] = []string{"foo", "bar"}
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -180,7 +204,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
|||||||
// Bad
|
// Bad
|
||||||
config["http_port_min"] = 1000
|
config["http_port_min"] = 1000
|
||||||
config["http_port_max"] = 500
|
config["http_port_max"] = 500
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -188,7 +215,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
|||||||
// Bad
|
// Bad
|
||||||
config["http_port_min"] = -500
|
config["http_port_min"] = -500
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -197,7 +227,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
|||||||
config["http_port_min"] = 500
|
config["http_port_min"] = 500
|
||||||
config["http_port_max"] = 1000
|
config["http_port_max"] = 1000
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -209,7 +242,10 @@ func TestBuilderPrepare_Format(t *testing.T) {
|
|||||||
|
|
||||||
// Bad
|
// Bad
|
||||||
config["format"] = "illegal value"
|
config["format"] = "illegal value"
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -217,7 +253,10 @@ func TestBuilderPrepare_Format(t *testing.T) {
|
|||||||
// Good
|
// Good
|
||||||
config["format"] = "qcow2"
|
config["format"] = "qcow2"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -225,7 +264,10 @@ func TestBuilderPrepare_Format(t *testing.T) {
|
|||||||
// Good
|
// Good
|
||||||
config["format"] = "raw"
|
config["format"] = "raw"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -237,7 +279,10 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
|||||||
|
|
||||||
// Add a random key
|
// Add a random key
|
||||||
config["i_should_not_be_valid"] = true
|
config["i_should_not_be_valid"] = true
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -249,7 +294,10 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
|
|||||||
|
|
||||||
// Test bad
|
// Test bad
|
||||||
config["iso_checksum"] = ""
|
config["iso_checksum"] = ""
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -257,7 +305,10 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
|
|||||||
// Test good
|
// Test good
|
||||||
config["iso_checksum"] = "FOo"
|
config["iso_checksum"] = "FOo"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -273,7 +324,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
|
|||||||
|
|
||||||
// Test bad
|
// Test bad
|
||||||
config["iso_checksum_type"] = ""
|
config["iso_checksum_type"] = ""
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -281,7 +335,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
|
|||||||
// Test good
|
// Test good
|
||||||
config["iso_checksum_type"] = "mD5"
|
config["iso_checksum_type"] = "mD5"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -293,7 +350,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
|
|||||||
// Test unknown
|
// Test unknown
|
||||||
config["iso_checksum_type"] = "fake"
|
config["iso_checksum_type"] = "fake"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -308,7 +368,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
|
|||||||
// Test both epty
|
// Test both epty
|
||||||
config["iso_url"] = ""
|
config["iso_url"] = ""
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -316,7 +379,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
|
|||||||
// Test iso_url set
|
// Test iso_url set
|
||||||
config["iso_url"] = "http://www.packer.io"
|
config["iso_url"] = "http://www.packer.io"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("should not have error: %s", err)
|
t.Errorf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -330,7 +396,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
|
|||||||
config["iso_url"] = "http://www.packer.io"
|
config["iso_url"] = "http://www.packer.io"
|
||||||
config["iso_urls"] = []string{"http://www.packer.io"}
|
config["iso_urls"] = []string{"http://www.packer.io"}
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -343,7 +412,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("should not have error: %s", err)
|
t.Errorf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -370,7 +442,10 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
|
|||||||
|
|
||||||
config["output_directory"] = dir
|
config["output_directory"] = dir
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -378,7 +453,10 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
|
|||||||
// Test with a good one
|
// Test with a good one
|
||||||
config["output_directory"] = "i-hope-i-dont-exist"
|
config["output_directory"] = "i-hope-i-dont-exist"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -390,7 +468,10 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
|
|||||||
|
|
||||||
// Test with a bad value
|
// Test with a bad value
|
||||||
config["shutdown_timeout"] = "this is not good"
|
config["shutdown_timeout"] = "this is not good"
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -398,7 +479,10 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
|
|||||||
// Test with a good one
|
// Test with a good one
|
||||||
config["shutdown_timeout"] = "5s"
|
config["shutdown_timeout"] = "5s"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -412,7 +496,10 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
|
|||||||
config["ssh_host_port_min"] = 1000
|
config["ssh_host_port_min"] = 1000
|
||||||
config["ssh_host_port_max"] = 500
|
config["ssh_host_port_max"] = 500
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -420,7 +507,10 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
|
|||||||
// Bad
|
// Bad
|
||||||
config["ssh_host_port_min"] = -500
|
config["ssh_host_port_min"] = -500
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -429,7 +519,10 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
|
|||||||
config["ssh_host_port_min"] = 500
|
config["ssh_host_port_min"] = 500
|
||||||
config["ssh_host_port_max"] = 1000
|
config["ssh_host_port_max"] = 1000
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -441,14 +534,20 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
|
|||||||
|
|
||||||
config["ssh_key_path"] = ""
|
config["ssh_key_path"] = ""
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config["ssh_key_path"] = "/i/dont/exist"
|
config["ssh_key_path"] = "/i/dont/exist"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -467,7 +566,10 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
|
|||||||
|
|
||||||
config["ssh_key_path"] = tf.Name()
|
config["ssh_key_path"] = tf.Name()
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -478,7 +580,10 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
|
|||||||
tf.Write([]byte(testPem))
|
tf.Write([]byte(testPem))
|
||||||
config["ssh_key_path"] = tf.Name()
|
config["ssh_key_path"] = tf.Name()
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
@ -490,14 +595,20 @@ func TestBuilderPrepare_SSHUser(t *testing.T) {
|
|||||||
|
|
||||||
config["ssh_username"] = ""
|
config["ssh_username"] = ""
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
|
|
||||||
config["ssh_username"] = "exists"
|
config["ssh_username"] = "exists"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -509,7 +620,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
|
|||||||
|
|
||||||
// Test a default boot_wait
|
// Test a default boot_wait
|
||||||
delete(config, "ssh_wait_timeout")
|
delete(config, "ssh_wait_timeout")
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
@ -521,7 +635,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
|
|||||||
// Test with a bad value
|
// Test with a bad value
|
||||||
config["ssh_wait_timeout"] = "this is not good"
|
config["ssh_wait_timeout"] = "this is not good"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("should have error")
|
t.Fatal("should have error")
|
||||||
}
|
}
|
||||||
@ -529,7 +646,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
|
|||||||
// Test with a good one
|
// Test with a good one
|
||||||
config["ssh_wait_timeout"] = "5s"
|
config["ssh_wait_timeout"] = "5s"
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
@ -541,7 +661,10 @@ func TestBuilderPrepare_QemuArgs(t *testing.T) {
|
|||||||
|
|
||||||
// Test with empty
|
// Test with empty
|
||||||
delete(config, "qemuargs")
|
delete(config, "qemuargs")
|
||||||
err := b.Prepare(config)
|
warns, err := b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("err: %s", err)
|
t.Fatalf("err: %s", err)
|
||||||
}
|
}
|
||||||
@ -556,7 +679,10 @@ func TestBuilderPrepare_QemuArgs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b = Builder{}
|
b = Builder{}
|
||||||
err = b.Prepare(config)
|
warns, err = b.Prepare(config)
|
||||||
|
if len(warns) > 0 {
|
||||||
|
t.Fatalf("bad: %#v", warns)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("should not have error: %s", err)
|
t.Fatalf("should not have error: %s", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user