builder/vmware: better tests around iso_url, test files

This commit is contained in:
Mitchell Hashimoto 2013-06-09 22:08:53 -07:00
parent 62309cb6de
commit 657c3fd87d
2 changed files with 24 additions and 1 deletions

View File

@ -125,6 +125,11 @@ func (b *Builder) Prepare(raw interface{}) (err error) {
} }
} }
} }
if len(errs) == 0 {
// Put the URL back together since we may have modified it
b.config.ISOUrl = url.String()
}
} }
if b.config.SSHUser == "" { if b.config.SSHUser == "" {
@ -192,6 +197,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) packer
// Setup the state bag // Setup the state bag
state := make(map[string]interface{}) state := make(map[string]interface{})
state["cache"] = cache
state["config"] = &b.config state["config"] = &b.config
state["driver"] = b.driver state["driver"] = b.driver
state["hook"] = hook state["hook"] = hook

View File

@ -2,6 +2,8 @@ package vmware
import ( import (
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"io/ioutil"
"os"
"testing" "testing"
"time" "time"
) )
@ -97,7 +99,6 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
var b Builder var b Builder
config := testConfig() config := testConfig()
// Test iso_url
config["iso_url"] = "" config["iso_url"] = ""
err := b.Prepare(config) err := b.Prepare(config)
if err == nil { if err == nil {
@ -121,6 +122,22 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("should not have error: %s", err) t.Errorf("should not have error: %s", err)
} }
tf, err := ioutil.TempFile("", "packer")
if err != nil {
t.Fatalf("error tempfile: %s", err)
}
defer os.Remove(tf.Name())
config["iso_url"] = tf.Name()
err = b.Prepare(config)
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if b.config.ISOUrl != "file://"+tf.Name() {
t.Fatalf("iso_url should be modified: %s", b.config.ISOUrl)
}
} }
func TestBuilderPrepare_ShutdownTimeout(t *testing.T) { func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {