Commit 64397f21 authored by Seth Vargo's avatar Seth Vargo

Merge pull request #1730 from ceh/issue-801

post-processor/vagrant: check if vagrantfile_template exists
parents a6375568 53b1db16
...@@ -210,6 +210,13 @@ func (p *PostProcessor) configureSingle(config *Config, raws ...interface{}) err ...@@ -210,6 +210,13 @@ func (p *PostProcessor) configureSingle(config *Config, raws ...interface{}) err
"vagrantfile_template": &config.VagrantfileTemplate, "vagrantfile_template": &config.VagrantfileTemplate,
} }
if config.VagrantfileTemplate != "" {
_, err := os.Stat(config.VagrantfileTemplate)
if err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("vagrantfile_template '%s' does not exist", config.VagrantfileTemplate))
}
}
for n, ptr := range validates { for n, ptr := range validates {
if err := config.tpl.Validate(*ptr); err != nil { if err := config.tpl.Validate(*ptr); err != nil {
errs = packer.MultiErrorAppend( errs = packer.MultiErrorAppend(
......
...@@ -84,16 +84,22 @@ func TestPostProcessorPrepare_outputPath(t *testing.T) { ...@@ -84,16 +84,22 @@ func TestPostProcessorPrepare_outputPath(t *testing.T) {
func TestPostProcessorPrepare_subConfigs(t *testing.T) { func TestPostProcessorPrepare_subConfigs(t *testing.T) {
var p PostProcessor var p PostProcessor
f, err := ioutil.TempFile("", "packer")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.Remove(f.Name())
// Default // Default
c := testConfig() c := testConfig()
c["compression_level"] = 42 c["compression_level"] = 42
c["vagrantfile_template"] = "foo" c["vagrantfile_template"] = f.Name()
c["override"] = map[string]interface{}{ c["override"] = map[string]interface{}{
"aws": map[string]interface{}{ "aws": map[string]interface{}{
"compression_level": 7, "compression_level": 7,
}, },
} }
err := p.Configure(c) err = p.Configure(c)
if err != nil { if err != nil {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
...@@ -102,7 +108,7 @@ func TestPostProcessorPrepare_subConfigs(t *testing.T) { ...@@ -102,7 +108,7 @@ func TestPostProcessorPrepare_subConfigs(t *testing.T) {
t.Fatalf("bad: %#v", p.configs[""].CompressionLevel) t.Fatalf("bad: %#v", p.configs[""].CompressionLevel)
} }
if p.configs[""].VagrantfileTemplate != "foo" { if p.configs[""].VagrantfileTemplate != f.Name() {
t.Fatalf("bad: %#v", p.configs[""].VagrantfileTemplate) t.Fatalf("bad: %#v", p.configs[""].VagrantfileTemplate)
} }
...@@ -110,11 +116,30 @@ func TestPostProcessorPrepare_subConfigs(t *testing.T) { ...@@ -110,11 +116,30 @@ func TestPostProcessorPrepare_subConfigs(t *testing.T) {
t.Fatalf("bad: %#v", p.configs["aws"].CompressionLevel) t.Fatalf("bad: %#v", p.configs["aws"].CompressionLevel)
} }
if p.configs["aws"].VagrantfileTemplate != "foo" { if p.configs["aws"].VagrantfileTemplate != f.Name() {
t.Fatalf("bad: %#v", p.configs["aws"].VagrantfileTemplate) t.Fatalf("bad: %#v", p.configs["aws"].VagrantfileTemplate)
} }
} }
func TestPostProcessorPrepare_vagrantfileTemplateExists(t *testing.T) {
var p PostProcessor
f, err := ioutil.TempFile("", "packer")
if err != nil {
t.Fatalf("err: %s", err)
}
c := testConfig()
c["vagrantfile_template"] = f.Name()
os.Remove(f.Name())
err = p.Configure(c)
if err == nil {
t.Fatal("expected an error since vagrantfile_template does not exist")
}
}
func TestPostProcessorPostProcess_badId(t *testing.T) { func TestPostProcessorPostProcess_badId(t *testing.T) {
artifact := &packer.MockArtifact{ artifact := &packer.MockArtifact{
BuilderIdValue: "invalid.packer", BuilderIdValue: "invalid.packer",
......
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