Commit a6150e65 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

builder/all: update to warnings

parent 3cd7379d
...@@ -49,15 +49,15 @@ type Builder struct { ...@@ -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 { ...@@ -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) {
......
...@@ -34,7 +34,10 @@ func TestBuilder_Prepare_BadType(t *testing.T) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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)
} }
......
...@@ -29,15 +29,15 @@ type Builder struct { ...@@ -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 { ...@@ -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) {
......
...@@ -32,7 +32,10 @@ func TestBuilder_Prepare_BadType(t *testing.T) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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) { ...@@ -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")
} }
......
...@@ -72,15 +72,15 @@ type config struct { ...@@ -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 { ...@@ -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) {
......
This diff is collapsed.
...@@ -66,15 +66,15 @@ type config struct { ...@@ -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 { ...@@ -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) {
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment