template: validate post-processor only/except

This commit is contained in:
Mitchell Hashimoto 2015-05-21 15:42:12 -06:00
parent 637fabc1c7
commit 28dc1c2aed
6 changed files with 73 additions and 0 deletions

View File

@ -109,6 +109,19 @@ func (t *Template) Validate() error {
} }
} }
// Verify post-processors
for i, chain := range t.PostProcessors {
for j, p := range chain {
// Validate only/except
if verr := p.OnlyExcept.Validate(t); verr != nil {
for _, e := range multierror.Append(verr).Errors {
err = multierror.Append(err, fmt.Errorf(
"post-processor %d.%d: %s", i+1, j+1, e))
}
}
}
}
return err return err
} }

View File

@ -52,6 +52,26 @@ func TestTemplateValidate(t *testing.T) {
"validate-good-prov-except.json", "validate-good-prov-except.json",
false, false,
}, },
{
"validate-bad-pp-only.json",
true,
},
{
"validate-good-pp-only.json",
false,
},
{
"validate-bad-pp-except.json",
true,
},
{
"validate-good-pp-except.json",
false,
},
} }
for _, tc := range cases { for _, tc := range cases {

View File

@ -0,0 +1,10 @@
{
"builders": [{
"type": "foo"
}],
"post-processors": [{
"type": "bar",
"except": ["bar"]
}]
}

View File

@ -0,0 +1,10 @@
{
"builders": [{
"type": "foo"
}],
"post-processors": [{
"type": "bar",
"only": ["bar"]
}]
}

View File

@ -0,0 +1,10 @@
{
"builders": [{
"type": "foo"
}],
"post-processors": [{
"type": "bar",
"except": ["foo"]
}]
}

View File

@ -0,0 +1,10 @@
{
"builders": [{
"type": "foo"
}],
"post-processors": [{
"type": "bar",
"only": ["foo"]
}]
}