This commit is contained in:
Chris Bednarski 2015-08-21 17:11:02 -07:00
commit b610e8005c
2 changed files with 36 additions and 11 deletions

View File

@ -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)
}

View File

@ -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 {