Commit 590997df authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: automatically validate when creating a core

parent e0a9215e
......@@ -49,11 +49,6 @@ func (m *Meta) Core(tpl *template.Template) (*packer.Core, error) {
return nil, fmt.Errorf("Error initializing core: %s", err)
}
// Validate it
if err := core.Validate(); err != nil {
return nil, err
}
return core, nil
}
......
......@@ -72,6 +72,9 @@ func NewCore(c *CoreConfig) (*Core, error) {
variables: c.Variables,
builds: builds,
}
if err := result.validate(); err != nil {
return nil, err
}
if err := result.init(); err != nil {
return nil, err
}
......@@ -205,11 +208,11 @@ func (c *Core) Build(n string) (Build, error) {
}, nil
}
// Validate does a full validation of the template.
// validate does a full validation of the template.
//
// This will automatically call template.Validate() in addition to doing
// This will automatically call template.validate() in addition to doing
// richer semantic checks around variables and so on.
func (c *Core) Validate() error {
func (c *Core) validate() error {
// First validate the template in general, we can't do anything else
// unless the template itself is valid.
if err := c.template.Validate(); err != nil {
......
......@@ -376,15 +376,11 @@ func TestCoreValidate(t *testing.T) {
t.Fatalf("err: %s\n\n%s", tc.File, err)
}
core, err := NewCore(&CoreConfig{
_, err = NewCore(&CoreConfig{
Template: tpl,
Variables: tc.Vars,
})
if err != nil {
t.Fatalf("err: %s\n\n%s", tc.File, err)
}
if err := core.Validate(); (err != nil) != tc.Err {
if (err != nil) != tc.Err {
t.Fatalf("err: %s\n\n%s", tc.File, err)
}
}
......
{
"builders": [{
"type": "test"
}, {
"name": "foo",
"type": "test"
}],
"provisioners": [{
......
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