post-processor/vagrant: validate the template
This commit is contained in:
parent
ef1378462c
commit
2291d5ba79
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue