diff --git a/builder/docker/config_test.go b/builder/docker/config_test.go index 907222b4f..442c6ffe2 100644 --- a/builder/docker/config_test.go +++ b/builder/docker/config_test.go @@ -52,10 +52,11 @@ func TestConfigPrepare_exportPath(t *testing.T) { raw := testConfig() - // No export path + // No export path. This is invalid. Previously this would not error during + // validation and as a result the failure would happen at build time. delete(raw, "export_path") _, warns, errs := NewConfig(raw) - testConfigOk(t, warns, errs) + testConfigErr(t, warns, errs) // Good export path raw["export_path"] = "good" @@ -70,14 +71,39 @@ func TestConfigPrepare_exportPath(t *testing.T) { func TestConfigPrepare_exportPathAndCommit(t *testing.T) { raw := testConfig() - raw["commit"] = true - // No export path + // Export but no commit (explicit default) + raw["commit"] = false _, warns, errs := NewConfig(raw) + testConfigOk(t, warns, errs) + + // Commit AND export specified (invalid) + raw["commit"] = true + _, warns, errs = NewConfig(raw) testConfigErr(t, warns, errs) - // No commit - raw["commit"] = false + // Commit but no export + delete(raw, "export_path") + _, warns, errs = NewConfig(raw) + testConfigOk(t, warns, errs) +} + +func TestConfigPrepare_exportDiscard(t *testing.T) { + raw := testConfig() + + // Export but no discard (explicit default) + raw["discard"] = false + _, warns, errs := NewConfig(raw) + testConfigOk(t, warns, errs) + + // Discard AND export (invalid) + raw["discard"] = true + _, warns, errs = NewConfig(raw) + testConfigErr(t, warns, errs) + + // Discard but no export + raw["discard"] = true + delete(raw, "export_path") _, warns, errs = NewConfig(raw) testConfigOk(t, warns, errs) } diff --git a/builder/qemu/builder.go b/builder/qemu/builder.go index 39984d68b..4ac22b59b 100644 --- a/builder/qemu/builder.go +++ b/builder/qemu/builder.go @@ -201,13 +201,12 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { b.config.VNCPortMax = 6000 } - if b.config.Format == "" { - b.config.Format = "qcow2" + if b.config.VMName == "" { + b.config.VMName = fmt.Sprintf("packer-%s", b.config.PackerBuildName) } - if b.config.VMName == "" { - b.config.VMName = fmt.Sprintf("packer-%s.%s", - b.config.PackerBuildName, b.config.Format) + if b.config.Format == "" { + b.config.Format = "qcow2" } if b.config.FloppyFiles == nil {