builder/all: update to warnings

This commit is contained in:
Mitchell Hashimoto 2013-11-02 23:03:59 -05:00
parent 3cd7379d1f
commit a6150e6596
8 changed files with 544 additions and 151 deletions

View File

@ -49,15 +49,15 @@ type Builder struct {
runner multistep.Runner runner multistep.Runner
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
md, err := common.DecodeConfig(&b.config, raws...) md, err := common.DecodeConfig(&b.config, raws...)
if err != nil { if err != nil {
return err return nil, err
} }
b.config.tpl, err = packer.NewConfigTemplate() b.config.tpl, err = packer.NewConfigTemplate()
if err != nil { if err != nil {
return err return nil, err
} }
b.config.tpl.UserVars = b.config.PackerUserVars b.config.tpl.UserVars = b.config.PackerUserVars
@ -161,11 +161,11 @@ func (b *Builder) Prepare(raws ...interface{}) error {
b.config.stateTimeout = stateTimeout b.config.stateTimeout = stateTimeout
if errs != nil && len(errs.Errors) > 0 { if errs != nil && len(errs.Errors) > 0 {
return errs return nil, errs
} }
common.ScrubConfig(b.config, b.config.ClientID, b.config.APIKey) common.ScrubConfig(b.config, b.config.ClientID, b.config.APIKey)
return nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {

View File

@ -34,7 +34,10 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"api_key": []string{}, "api_key": []string{},
} }
err := b.Prepare(c) warnings, err := b.Prepare(c)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err == nil { if err == nil {
t.Fatalf("prepare should fail") t.Fatalf("prepare should fail")
} }
@ -46,7 +49,10 @@ func TestBuilderPrepare_APIKey(t *testing.T) {
// Test good // Test good
config["api_key"] = "foo" config["api_key"] = "foo"
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -58,7 +64,10 @@ func TestBuilderPrepare_APIKey(t *testing.T) {
// Test bad // Test bad
delete(config, "api_key") delete(config, "api_key")
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -67,7 +76,10 @@ func TestBuilderPrepare_APIKey(t *testing.T) {
delete(config, "api_key") delete(config, "api_key")
os.Setenv("DIGITALOCEAN_API_KEY", "foo") os.Setenv("DIGITALOCEAN_API_KEY", "foo")
defer os.Setenv("DIGITALOCEAN_API_KEY", "") defer os.Setenv("DIGITALOCEAN_API_KEY", "")
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -79,7 +91,10 @@ func TestBuilderPrepare_ClientID(t *testing.T) {
// Test good // Test good
config["client_id"] = "foo" config["client_id"] = "foo"
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -91,7 +106,10 @@ func TestBuilderPrepare_ClientID(t *testing.T) {
// Test bad // Test bad
delete(config, "client_id") delete(config, "client_id")
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -100,7 +118,10 @@ func TestBuilderPrepare_ClientID(t *testing.T) {
delete(config, "client_id") delete(config, "client_id")
os.Setenv("DIGITALOCEAN_CLIENT_ID", "foo") os.Setenv("DIGITALOCEAN_CLIENT_ID", "foo")
defer os.Setenv("DIGITALOCEAN_CLIENT_ID", "") defer os.Setenv("DIGITALOCEAN_CLIENT_ID", "")
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -112,7 +133,10 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key // Add a random key
config["i_should_not_be_valid"] = true config["i_should_not_be_valid"] = true
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -123,7 +147,10 @@ func TestBuilderPrepare_RegionID(t *testing.T) {
config := testConfig() config := testConfig()
// Test default // Test default
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -135,7 +162,10 @@ func TestBuilderPrepare_RegionID(t *testing.T) {
// Test set // Test set
config["region_id"] = 2 config["region_id"] = 2
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -150,7 +180,10 @@ func TestBuilderPrepare_SizeID(t *testing.T) {
config := testConfig() config := testConfig()
// Test default // Test default
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -162,7 +195,10 @@ func TestBuilderPrepare_SizeID(t *testing.T) {
// Test set // Test set
config["size_id"] = 67 config["size_id"] = 67
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -177,7 +213,10 @@ func TestBuilderPrepare_ImageID(t *testing.T) {
config := testConfig() config := testConfig()
// Test default // Test default
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -189,7 +228,10 @@ func TestBuilderPrepare_ImageID(t *testing.T) {
// Test set // Test set
config["size_id"] = 2 config["size_id"] = 2
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -204,7 +246,10 @@ func TestBuilderPrepare_SSHUsername(t *testing.T) {
config := testConfig() config := testConfig()
// Test default // Test default
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -216,7 +261,10 @@ func TestBuilderPrepare_SSHUsername(t *testing.T) {
// Test set // Test set
config["ssh_username"] = "foo" config["ssh_username"] = "foo"
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -231,7 +279,10 @@ func TestBuilderPrepare_SSHTimeout(t *testing.T) {
config := testConfig() config := testConfig()
// Test default // Test default
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -243,7 +294,10 @@ func TestBuilderPrepare_SSHTimeout(t *testing.T) {
// Test set // Test set
config["ssh_timeout"] = "30s" config["ssh_timeout"] = "30s"
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -251,7 +305,10 @@ func TestBuilderPrepare_SSHTimeout(t *testing.T) {
// Test bad // Test bad
config["ssh_timeout"] = "tubes" config["ssh_timeout"] = "tubes"
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -263,7 +320,10 @@ func TestBuilderPrepare_StateTimeout(t *testing.T) {
config := testConfig() config := testConfig()
// Test default // Test default
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -275,7 +335,10 @@ func TestBuilderPrepare_StateTimeout(t *testing.T) {
// Test set // Test set
config["state_timeout"] = "5m" config["state_timeout"] = "5m"
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -283,7 +346,10 @@ func TestBuilderPrepare_StateTimeout(t *testing.T) {
// Test bad // Test bad
config["state_timeout"] = "tubes" config["state_timeout"] = "tubes"
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -295,7 +361,10 @@ func TestBuilderPrepare_SnapshotName(t *testing.T) {
config := testConfig() config := testConfig()
// Test default // Test default
err := b.Prepare(config) warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -307,7 +376,10 @@ func TestBuilderPrepare_SnapshotName(t *testing.T) {
// Test set // Test set
config["snapshot_name"] = "foobarbaz" config["snapshot_name"] = "foobarbaz"
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -315,7 +387,10 @@ func TestBuilderPrepare_SnapshotName(t *testing.T) {
// Test set with template // Test set with template
config["snapshot_name"] = "{{timestamp}}" config["snapshot_name"] = "{{timestamp}}"
b = Builder{} b = Builder{}
err = b.Prepare(config) warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }

View File

@ -29,15 +29,15 @@ type Builder struct {
runner multistep.Runner runner multistep.Runner
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
md, err := common.DecodeConfig(&b.config, raws...) md, err := common.DecodeConfig(&b.config, raws...)
if err != nil { if err != nil {
return err return nil, err
} }
b.config.tpl, err = packer.NewConfigTemplate() b.config.tpl, err = packer.NewConfigTemplate()
if err != nil { if err != nil {
return err return nil, err
} }
b.config.tpl.UserVars = b.config.PackerUserVars b.config.tpl.UserVars = b.config.PackerUserVars
@ -48,11 +48,11 @@ func (b *Builder) Prepare(raws ...interface{}) error {
errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...) errs = packer.MultiErrorAppend(errs, b.config.RunConfig.Prepare(b.config.tpl)...)
if errs != nil && len(errs.Errors) > 0 { if errs != nil && len(errs.Errors) > 0 {
return errs return nil, errs
} }
log.Println(common.ScrubConfig(b.config, b.config.Password)) log.Println(common.ScrubConfig(b.config, b.config.Password))
return nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {

View File

@ -32,7 +32,10 @@ func TestBuilder_Prepare_BadType(t *testing.T) {
"password": []string{}, "password": []string{},
} }
err := b.Prepare(c) warns, err := b.Prepare(c)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatalf("prepare should fail") t.Fatalf("prepare should fail")
} }
@ -44,7 +47,10 @@ func TestBuilderPrepare_ImageName(t *testing.T) {
// Test good // Test good
config["image_name"] = "foo" config["image_name"] = "foo"
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -52,7 +58,10 @@ func TestBuilderPrepare_ImageName(t *testing.T) {
// Test bad // Test bad
config["image_name"] = "foo {{" config["image_name"] = "foo {{"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -60,7 +69,10 @@ func TestBuilderPrepare_ImageName(t *testing.T) {
// Test bad // Test bad
delete(config, "image_name") delete(config, "image_name")
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -72,7 +84,10 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key // Add a random key
config["i_should_not_be_valid"] = true config["i_should_not_be_valid"] = true
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }

View File

@ -72,15 +72,15 @@ type config struct {
tpl *packer.ConfigTemplate tpl *packer.ConfigTemplate
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
md, err := common.DecodeConfig(&b.config, raws...) md, err := common.DecodeConfig(&b.config, raws...)
if err != nil { if err != nil {
return err return nil, err
} }
b.config.tpl, err = packer.NewConfigTemplate() b.config.tpl, err = packer.NewConfigTemplate()
if err != nil { if err != nil {
return err return nil, err
} }
b.config.tpl.UserVars = b.config.PackerUserVars b.config.tpl.UserVars = b.config.PackerUserVars
@ -364,10 +364,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
} }
if errs != nil && len(errs.Errors) > 0 { if errs != nil && len(errs.Errors) > 0 {
return errs return nil, errs
} }
return nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {

View File

@ -60,7 +60,10 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
func TestBuilderPrepare_Defaults(t *testing.T) { func TestBuilderPrepare_Defaults(t *testing.T) {
var b Builder var b Builder
config := testConfig() config := testConfig()
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -104,7 +107,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
// Test a default boot_wait // Test a default boot_wait
delete(config, "boot_wait") delete(config, "boot_wait")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -115,7 +121,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
// Test with a bad boot_wait // Test with a bad boot_wait
config["boot_wait"] = "this is not good" config["boot_wait"] = "this is not good"
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -123,7 +132,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
// Test with a good one // Test with a good one
config["boot_wait"] = "5s" config["boot_wait"] = "5s"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -134,7 +146,10 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config := testConfig() config := testConfig()
delete(config, "disk_size") delete(config, "disk_size")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("bad err: %s", err) t.Fatalf("bad err: %s", err)
} }
@ -145,7 +160,10 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config["disk_size"] = 60000 config["disk_size"] = 60000
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -160,7 +178,10 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config := testConfig() config := testConfig()
delete(config, "floppy_files") delete(config, "floppy_files")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("bad err: %s", err) t.Fatalf("bad err: %s", err)
} }
@ -171,7 +192,10 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config["floppy_files"] = []string{"foo", "bar"} config["floppy_files"] = []string{"foo", "bar"}
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -188,7 +212,10 @@ func TestBuilderPrepare_GuestAdditionsMode(t *testing.T) {
// test default mode // test default mode
delete(config, "guest_additions_mode") delete(config, "guest_additions_mode")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("bad err: %s", err) t.Fatalf("bad err: %s", err)
} }
@ -196,7 +223,10 @@ func TestBuilderPrepare_GuestAdditionsMode(t *testing.T) {
// Test another mode // Test another mode
config["guest_additions_mode"] = "attach" config["guest_additions_mode"] = "attach"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -208,7 +238,10 @@ func TestBuilderPrepare_GuestAdditionsMode(t *testing.T) {
// Test bad mode // Test bad mode
config["guest_additions_mode"] = "teleport" config["guest_additions_mode"] = "teleport"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should error") t.Fatal("should error")
} }
@ -219,7 +252,10 @@ func TestBuilderPrepare_GuestAdditionsPath(t *testing.T) {
config := testConfig() config := testConfig()
delete(config, "guest_additions_path") delete(config, "guest_additions_path")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("bad err: %s", err) t.Fatalf("bad err: %s", err)
} }
@ -230,7 +266,10 @@ func TestBuilderPrepare_GuestAdditionsPath(t *testing.T) {
config["guest_additions_path"] = "foo" config["guest_additions_path"] = "foo"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -245,7 +284,10 @@ func TestBuilderPrepare_GuestAdditionsSHA256(t *testing.T) {
config := testConfig() config := testConfig()
delete(config, "guest_additions_sha256") delete(config, "guest_additions_sha256")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("bad err: %s", err) t.Fatalf("bad err: %s", err)
} }
@ -256,7 +298,10 @@ func TestBuilderPrepare_GuestAdditionsSHA256(t *testing.T) {
config["guest_additions_sha256"] = "FOO" config["guest_additions_sha256"] = "FOO"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -271,7 +316,10 @@ func TestBuilderPrepare_GuestAdditionsURL(t *testing.T) {
config := testConfig() config := testConfig()
config["guest_additions_url"] = "" config["guest_additions_url"] = ""
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -282,7 +330,10 @@ func TestBuilderPrepare_GuestAdditionsURL(t *testing.T) {
config["guest_additions_url"] = "http://www.packer.io" config["guest_additions_url"] = "http://www.packer.io"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Errorf("should not have error: %s", err) t.Errorf("should not have error: %s", err)
} }
@ -294,7 +345,10 @@ func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
// Test a default boot_wait // Test a default boot_wait
delete(config, "hard_drive_interface") delete(config, "hard_drive_interface")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -306,7 +360,10 @@ func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
// Test with a bad // Test with a bad
config["hard_drive_interface"] = "fake" config["hard_drive_interface"] = "fake"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -314,7 +371,10 @@ func TestBuilderPrepare_HardDriveInterface(t *testing.T) {
// Test with a good // Test with a good
config["hard_drive_interface"] = "sata" config["hard_drive_interface"] = "sata"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -327,7 +387,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
// Bad // Bad
config["http_port_min"] = 1000 config["http_port_min"] = 1000
config["http_port_max"] = 500 config["http_port_max"] = 500
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -335,7 +398,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
// Bad // Bad
config["http_port_min"] = -500 config["http_port_min"] = -500
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -344,7 +410,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
config["http_port_min"] = 500 config["http_port_min"] = 500
config["http_port_max"] = 1000 config["http_port_max"] = 1000
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -356,7 +425,10 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Bad // Bad
config["format"] = "illegal value" config["format"] = "illegal value"
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -364,7 +436,10 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Good // Good
config["format"] = "ova" config["format"] = "ova"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -372,7 +447,10 @@ func TestBuilderPrepare_Format(t *testing.T) {
// Good // Good
config["format"] = "ovf" config["format"] = "ovf"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -384,7 +462,10 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key // Add a random key
config["i_should_not_be_valid"] = true config["i_should_not_be_valid"] = true
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -396,7 +477,10 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test bad // Test bad
config["iso_checksum"] = "" config["iso_checksum"] = ""
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -404,7 +488,10 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test good // Test good
config["iso_checksum"] = "FOo" config["iso_checksum"] = "FOo"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -420,7 +507,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test bad // Test bad
config["iso_checksum_type"] = "" config["iso_checksum_type"] = ""
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -428,7 +518,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test good // Test good
config["iso_checksum_type"] = "mD5" config["iso_checksum_type"] = "mD5"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -440,7 +533,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test unknown // Test unknown
config["iso_checksum_type"] = "fake" config["iso_checksum_type"] = "fake"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -455,7 +551,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test both epty // Test both epty
config["iso_url"] = "" config["iso_url"] = ""
b = Builder{} b = Builder{}
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -463,7 +562,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test iso_url set // Test iso_url set
config["iso_url"] = "http://www.packer.io" config["iso_url"] = "http://www.packer.io"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Errorf("should not have error: %s", err) t.Errorf("should not have error: %s", err)
} }
@ -477,7 +579,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
config["iso_url"] = "http://www.packer.io" config["iso_url"] = "http://www.packer.io"
config["iso_urls"] = []string{"http://www.packer.io"} config["iso_urls"] = []string{"http://www.packer.io"}
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -490,7 +595,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
} }
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Errorf("should not have error: %s", err) t.Errorf("should not have error: %s", err)
} }
@ -517,7 +625,10 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
config["output_directory"] = dir config["output_directory"] = dir
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -525,7 +636,10 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
// Test with a good one // Test with a good one
config["output_directory"] = "i-hope-i-dont-exist" config["output_directory"] = "i-hope-i-dont-exist"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -537,7 +651,10 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
// Test with a bad value // Test with a bad value
config["shutdown_timeout"] = "this is not good" config["shutdown_timeout"] = "this is not good"
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -545,7 +662,10 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
// Test with a good one // Test with a good one
config["shutdown_timeout"] = "5s" config["shutdown_timeout"] = "5s"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -559,7 +679,10 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
config["ssh_host_port_min"] = 1000 config["ssh_host_port_min"] = 1000
config["ssh_host_port_max"] = 500 config["ssh_host_port_max"] = 500
b = Builder{} b = Builder{}
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -567,7 +690,10 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
// Bad // Bad
config["ssh_host_port_min"] = -500 config["ssh_host_port_min"] = -500
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -576,7 +702,10 @@ func TestBuilderPrepare_SSHHostPort(t *testing.T) {
config["ssh_host_port_min"] = 500 config["ssh_host_port_min"] = 500
config["ssh_host_port_max"] = 1000 config["ssh_host_port_max"] = 1000
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -588,14 +717,20 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
config["ssh_key_path"] = "" config["ssh_key_path"] = ""
b = Builder{} b = Builder{}
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
config["ssh_key_path"] = "/i/dont/exist" config["ssh_key_path"] = "/i/dont/exist"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -614,7 +749,10 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
config["ssh_key_path"] = tf.Name() config["ssh_key_path"] = tf.Name()
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -625,7 +763,10 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
tf.Write([]byte(testPem)) tf.Write([]byte(testPem))
config["ssh_key_path"] = tf.Name() config["ssh_key_path"] = tf.Name()
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -637,14 +778,20 @@ func TestBuilderPrepare_SSHUser(t *testing.T) {
config["ssh_username"] = "" config["ssh_username"] = ""
b = Builder{} b = Builder{}
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
config["ssh_username"] = "exists" config["ssh_username"] = "exists"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -656,7 +803,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test a default boot_wait // Test a default boot_wait
delete(config, "ssh_wait_timeout") delete(config, "ssh_wait_timeout")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -668,7 +818,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test with a bad value // Test with a bad value
config["ssh_wait_timeout"] = "this is not good" config["ssh_wait_timeout"] = "this is not good"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -676,7 +829,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test with a good one // Test with a good one
config["ssh_wait_timeout"] = "5s" config["ssh_wait_timeout"] = "5s"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -688,7 +844,10 @@ func TestBuilderPrepare_VBoxManage(t *testing.T) {
// Test with empty // Test with empty
delete(config, "vboxmanage") delete(config, "vboxmanage")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -703,7 +862,10 @@ func TestBuilderPrepare_VBoxManage(t *testing.T) {
} }
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -723,7 +885,10 @@ func TestBuilderPrepare_VBoxVersionFile(t *testing.T) {
// Test empty // Test empty
delete(config, "virtualbox_version_file") delete(config, "virtualbox_version_file")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -735,7 +900,10 @@ func TestBuilderPrepare_VBoxVersionFile(t *testing.T) {
// Test with a good one // Test with a good one
config["virtualbox_version_file"] = "foo" config["virtualbox_version_file"] = "foo"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }

View File

@ -66,15 +66,15 @@ type config struct {
tpl *packer.ConfigTemplate tpl *packer.ConfigTemplate
} }
func (b *Builder) Prepare(raws ...interface{}) error { func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
md, err := common.DecodeConfig(&b.config, raws...) md, err := common.DecodeConfig(&b.config, raws...)
if err != nil { if err != nil {
return err return nil, err
} }
b.config.tpl, err = packer.NewConfigTemplate() b.config.tpl, err = packer.NewConfigTemplate()
if err != nil { if err != nil {
return err return nil, err
} }
b.config.tpl.UserVars = b.config.PackerUserVars b.config.tpl.UserVars = b.config.PackerUserVars
@ -327,10 +327,10 @@ func (b *Builder) Prepare(raws ...interface{}) error {
} }
if errs != nil && len(errs.Errors) > 0 { if errs != nil && len(errs.Errors) > 0 {
return errs return nil, errs
} }
return nil return nil, nil
} }
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {

View File

@ -64,7 +64,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
// Test a default boot_wait // Test a default boot_wait
delete(config, "boot_wait") delete(config, "boot_wait")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -75,7 +78,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
// Test with a bad boot_wait // Test with a bad boot_wait
config["boot_wait"] = "this is not good" config["boot_wait"] = "this is not good"
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -83,7 +89,10 @@ func TestBuilderPrepare_BootWait(t *testing.T) {
// Test with a good one // Test with a good one
config["boot_wait"] = "5s" config["boot_wait"] = "5s"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -95,7 +104,10 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test bad // Test bad
config["iso_checksum"] = "" config["iso_checksum"] = ""
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -103,7 +115,10 @@ func TestBuilderPrepare_ISOChecksum(t *testing.T) {
// Test good // Test good
config["iso_checksum"] = "FOo" config["iso_checksum"] = "FOo"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -119,7 +134,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test bad // Test bad
config["iso_checksum_type"] = "" config["iso_checksum_type"] = ""
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -127,7 +145,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test good // Test good
config["iso_checksum_type"] = "mD5" config["iso_checksum_type"] = "mD5"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -139,7 +160,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
// Test unknown // Test unknown
config["iso_checksum_type"] = "fake" config["iso_checksum_type"] = "fake"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -147,7 +171,10 @@ func TestBuilderPrepare_ISOChecksumType(t *testing.T) {
func TestBuilderPrepare_Defaults(t *testing.T) { func TestBuilderPrepare_Defaults(t *testing.T) {
var b Builder var b Builder
config := testConfig() config := testConfig()
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -174,7 +201,10 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config := testConfig() config := testConfig()
delete(config, "disk_size") delete(config, "disk_size")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("bad err: %s", err) t.Fatalf("bad err: %s", err)
} }
@ -185,7 +215,10 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
config["disk_size"] = 60000 config["disk_size"] = 60000
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -200,7 +233,10 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config := testConfig() config := testConfig()
delete(config, "floppy_files") delete(config, "floppy_files")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("bad err: %s", err) t.Fatalf("bad err: %s", err)
} }
@ -211,7 +247,10 @@ func TestBuilderPrepare_FloppyFiles(t *testing.T) {
config["floppy_files"] = []string{"foo", "bar"} config["floppy_files"] = []string{"foo", "bar"}
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -229,7 +268,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
// Bad // Bad
config["http_port_min"] = 1000 config["http_port_min"] = 1000
config["http_port_max"] = 500 config["http_port_max"] = 500
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -237,7 +279,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
// Bad // Bad
config["http_port_min"] = -500 config["http_port_min"] = -500
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -246,7 +291,10 @@ func TestBuilderPrepare_HTTPPort(t *testing.T) {
config["http_port_min"] = 500 config["http_port_min"] = 500
config["http_port_max"] = 1000 config["http_port_max"] = 1000
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -258,7 +306,10 @@ func TestBuilderPrepare_InvalidKey(t *testing.T) {
// Add a random key // Add a random key
config["i_should_not_be_valid"] = true config["i_should_not_be_valid"] = true
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -273,7 +324,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test both epty // Test both epty
config["iso_url"] = "" config["iso_url"] = ""
b = Builder{} b = Builder{}
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -281,7 +335,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
// Test iso_url set // Test iso_url set
config["iso_url"] = "http://www.packer.io" config["iso_url"] = "http://www.packer.io"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Errorf("should not have error: %s", err) t.Errorf("should not have error: %s", err)
} }
@ -295,7 +352,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
config["iso_url"] = "http://www.packer.io" config["iso_url"] = "http://www.packer.io"
config["iso_urls"] = []string{"http://www.packer.io"} config["iso_urls"] = []string{"http://www.packer.io"}
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -308,7 +368,10 @@ func TestBuilderPrepare_ISOUrl(t *testing.T) {
} }
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Errorf("should not have error: %s", err) t.Errorf("should not have error: %s", err)
} }
@ -335,7 +398,10 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
config["output_directory"] = dir config["output_directory"] = dir
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -343,7 +409,10 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
// Test with a good one // Test with a good one
config["output_directory"] = "i-hope-i-dont-exist" config["output_directory"] = "i-hope-i-dont-exist"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -355,7 +424,10 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
// Test with a bad value // Test with a bad value
config["shutdown_timeout"] = "this is not good" config["shutdown_timeout"] = "this is not good"
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -363,7 +435,10 @@ func TestBuilderPrepare_ShutdownTimeout(t *testing.T) {
// Test with a good one // Test with a good one
config["shutdown_timeout"] = "5s" config["shutdown_timeout"] = "5s"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -375,14 +450,20 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
config["ssh_key_path"] = "" config["ssh_key_path"] = ""
b = Builder{} b = Builder{}
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
config["ssh_key_path"] = "/i/dont/exist" config["ssh_key_path"] = "/i/dont/exist"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -401,7 +482,10 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
config["ssh_key_path"] = tf.Name() config["ssh_key_path"] = tf.Name()
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -412,7 +496,10 @@ func TestBuilderPrepare_sshKeyPath(t *testing.T) {
tf.Write([]byte(testPem)) tf.Write([]byte(testPem))
config["ssh_key_path"] = tf.Name() config["ssh_key_path"] = tf.Name()
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -423,14 +510,20 @@ func TestBuilderPrepare_SSHUser(t *testing.T) {
config := testConfig() config := testConfig()
config["ssh_username"] = "" config["ssh_username"] = ""
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
config["ssh_username"] = "exists" config["ssh_username"] = "exists"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -442,7 +535,10 @@ func TestBuilderPrepare_SSHPort(t *testing.T) {
// Test with a bad value // Test with a bad value
delete(config, "ssh_port") delete(config, "ssh_port")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("bad err: %s", err) t.Fatalf("bad err: %s", err)
} }
@ -454,7 +550,10 @@ func TestBuilderPrepare_SSHPort(t *testing.T) {
// Test with a good one // Test with a good one
config["ssh_port"] = 44 config["ssh_port"] = 44
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -470,7 +569,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test with a bad value // Test with a bad value
config["ssh_wait_timeout"] = "this is not good" config["ssh_wait_timeout"] = "this is not good"
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -478,7 +580,10 @@ func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
// Test with a good one // Test with a good one
config["ssh_wait_timeout"] = "5s" config["ssh_wait_timeout"] = "5s"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -490,7 +595,10 @@ func TestBuilderPrepare_ToolsUploadPath(t *testing.T) {
// Test a default // Test a default
delete(config, "tools_upload_path") delete(config, "tools_upload_path")
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
@ -502,7 +610,10 @@ func TestBuilderPrepare_ToolsUploadPath(t *testing.T) {
// Test with a bad value // Test with a bad value
config["tools_upload_path"] = "{{{nope}" config["tools_upload_path"] = "{{{nope}"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -510,7 +621,10 @@ func TestBuilderPrepare_ToolsUploadPath(t *testing.T) {
// Test with a good one // Test with a good one
config["tools_upload_path"] = "hey" config["tools_upload_path"] = "hey"
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -522,7 +636,10 @@ func TestBuilderPrepare_VMXTemplatePath(t *testing.T) {
// Test bad // Test bad
config["vmx_template_path"] = "/i/dont/exist/forreal" config["vmx_template_path"] = "/i/dont/exist/forreal"
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -541,7 +658,10 @@ func TestBuilderPrepare_VMXTemplatePath(t *testing.T) {
config["vmx_template_path"] = tf.Name() config["vmx_template_path"] = tf.Name()
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -560,7 +680,10 @@ func TestBuilderPrepare_VMXTemplatePath(t *testing.T) {
config["vmx_template_path"] = tf2.Name() config["vmx_template_path"] = tf2.Name()
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -573,7 +696,10 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
// Bad // Bad
config["vnc_port_min"] = 1000 config["vnc_port_min"] = 1000
config["vnc_port_max"] = 500 config["vnc_port_max"] = 500
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -581,7 +707,10 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
// Bad // Bad
config["vnc_port_min"] = -500 config["vnc_port_min"] = -500
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil { if err == nil {
t.Fatal("should have error") t.Fatal("should have error")
} }
@ -590,7 +719,10 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
config["vnc_port_min"] = 500 config["vnc_port_min"] = 500
config["vnc_port_max"] = 1000 config["vnc_port_max"] = 1000
b = Builder{} b = Builder{}
err = b.Prepare(config) warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }
@ -605,7 +737,10 @@ func TestBuilderPrepare_VMXData(t *testing.T) {
"two": "bar", "two": "bar",
} }
err := b.Prepare(config) warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil { if err != nil {
t.Fatalf("should not have error: %s", err) t.Fatalf("should not have error: %s", err)
} }