packer: automatically validate when creating a core
This commit is contained in:
parent
e0a9215e47
commit
590997df44
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "test"
|
||||
}, {
|
||||
"name": "foo",
|
||||
"type": "test"
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
|
|
Loading…
Reference in New Issue