Skip to content

Commit

Permalink
Merge pull request hashicorp#4563 from marema31/vmware-iso-warn-esx
Browse files Browse the repository at this point in the history
builder/vmware-iso: Fail on wrong remote_type value
  • Loading branch information
SwampDragons authored Apr 6, 2018
2 parents 8850a6e + 5c11a2e commit 8316271
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
4 changes: 4 additions & 0 deletions builder/vmware/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,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 != "" {
Expand Down
52 changes: 52 additions & 0 deletions builder/vmware/iso/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,58 @@ 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"] = ""
// 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)
}

// 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()
Expand Down

0 comments on commit 8316271

Please sign in to comment.