builder/vmware-esxi: Add format validation and step_export tests

This commit is contained in:
Mark Peek 2015-10-23 16:50:14 -07:00
parent e80b3c6321
commit 9d0c443ca2
3 changed files with 71 additions and 0 deletions

View File

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

View File

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

View File

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