Commit 838abe40 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

post-processor/vagrant: validate the template

parent 6f3d0f6b
......@@ -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{})
......
......@@ -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")
}
}
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