Validate the remote_type value for builder/vmware-iso

This commit is contained in:
Marc Carmier 2017-02-15 22:04:28 +01:00
parent 99ffcfc269
commit 86c0c859c5
2 changed files with 44 additions and 0 deletions

4
builder/vmware/iso/builder.go Executable file → Normal file
View File

@ -162,6 +162,10 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("remote_host must be specified"))
}
if b.config.RemoteType != "esx5" {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Only 'esx5' value is accepted for remote_type"))
}
}
if b.config.Format != "" {

View File

@ -139,6 +139,46 @@ func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
}
}
func TestBuilderPrepare_RemoteType(t *testing.T) {
var b Builder
config := testConfig()
config["format"] = "ovf"
config["remote_host"] = "foobar.example.com"
// Bad
config["remote_type"] = "foobar"
warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil {
t.Fatal("should have error")
}
config["remote_host"] = ""
config["remote_type"] = "esx5"
// Bad
warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil {
t.Fatal("should have error")
}
// Good
config["remote_type"] = "esx5"
config["remote_host"] = "foobar.example.com"
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_Format(t *testing.T) {
var b Builder
config := testConfig()