diff --git a/builder/vmware/iso/builder.go b/builder/vmware/iso/builder.go index 617e1579b..4c8e74810 100755 --- a/builder/vmware/iso/builder.go +++ b/builder/vmware/iso/builder.go @@ -202,6 +202,13 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) { } } + if b.config.Format != "" { + if !(b.config.Format == "ova" || b.config.Format == "ovf" || b.config.Format == "vmx") { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("format must be one of ova, ovf, or vmx")) + } + } + // Warnings if b.config.ISOChecksumType == "none" { warnings = append(warnings, diff --git a/builder/vmware/iso/builder_test.go b/builder/vmware/iso/builder_test.go index 13a9622f7..ecc012fe0 100644 --- a/builder/vmware/iso/builder_test.go +++ b/builder/vmware/iso/builder_test.go @@ -208,6 +208,36 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) { } } +func TestBuilderPrepare_Format(t *testing.T) { + var b Builder + config := testConfig() + + // Bad + config["format"] = "foobar" + warns, err := b.Prepare(config) + if len(warns) > 0 { + t.Fatalf("bad: %#v", warns) + } + if err == nil { + t.Fatal("should have error") + } + + goodFormats := []string{"ova", "ovf", "vmx"} + + for _, format := range goodFormats { + // Good + config["format"] = format + b = Builder{} + 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) + } + } +} + func TestBuilderPrepare_HTTPPort(t *testing.T) { var b Builder config := testConfig() diff --git a/builder/vmware/iso/step_export_test.go b/builder/vmware/iso/step_export_test.go new file mode 100644 index 000000000..9ea0d64b9 --- /dev/null +++ b/builder/vmware/iso/step_export_test.go @@ -0,0 +1,34 @@ +package iso + +import ( + "github.com/mitchellh/multistep" + "testing" +) + +func TestStepExport_impl(t *testing.T) { + var _ multistep.Step = new(StepExport) +} + +func testStepExport_wrongtype_impl(t *testing.T, remoteType string) { + state := testState(t) + step := new(StepExport) + + var config Config + config.RemoteType = "foo" + state.Put("config", &config) + + if action := step.Run(state); action != multistep.ActionContinue { + t.Fatalf("bad action: %#v", action) + } + if _, ok := state.GetOk("error"); ok { + t.Fatal("should NOT have error") + } + + // Cleanup + step.Cleanup(state) +} + +func TestStepExport_wrongtype_impl(t *testing.T) { + testStepExport_wrongtype_impl(t, "foo") + testStepExport_wrongtype_impl(t, "") +}