post-processor/vagrant: validate the template

This commit is contained in:
Mitchell Hashimoto 2013-06-27 10:53:43 -07:00
parent ef1378462c
commit 2291d5ba79
2 changed files with 16 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"log"
"text/template"
)
var builtins = map[string]string{
@ -31,7 +32,12 @@ func (p *PostProcessor) Configure(raw interface{}) error {
}
if p.config.OutputPath == "" {
return fmt.Errorf("`output` must be specified.")
p.config.OutputPath = "packer_{{.Provider}}.box"
}
_, err = template.New("output").Parse(p.config.OutputPath)
if err != nil {
return fmt.Errorf("output invalid template: %s", err)
}
mapConfig, ok := raw.(map[string]interface{})

View File

@ -20,10 +20,18 @@ func TestPostProcessor_ImplementsPostProcessor(t *testing.T) {
func TestBuilderPrepare_OutputPath(t *testing.T) {
var p PostProcessor
// Default
c := testConfig()
delete(c, "output")
err := p.Configure(c)
if err != nil {
t.Fatalf("err: %s", err)
}
// Bad template
c["output"] = "bad {{{{.Template}}}}"
err = p.Configure(c)
if err == nil {
t.Fatalf("configure should fail")
t.Fatal("should have error")
}
}