diff --git a/provisioner/puppet-masterless/provisioner.go b/provisioner/puppet-masterless/provisioner.go index 5a0288cba..682aa584e 100644 --- a/provisioner/puppet-masterless/provisioner.go +++ b/provisioner/puppet-masterless/provisioner.go @@ -122,6 +122,17 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { } } + for i, path := range p.config.ModulePaths { + info, err := os.Stat(path) + if err != nil { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("module_path[%d] is invalid: %s", i, err)) + } else if !info.IsDir() { + errs = packer.MultiErrorAppend(errs, + fmt.Errorf("module_path[%d] must point to a directory")) + } + } + if errs != nil && len(errs.Errors) > 0 { return errs } diff --git a/provisioner/puppet-masterless/provisioner_test.go b/provisioner/puppet-masterless/provisioner_test.go index e2e4b3c96..88dea6029 100644 --- a/provisioner/puppet-masterless/provisioner_test.go +++ b/provisioner/puppet-masterless/provisioner_test.go @@ -2,12 +2,19 @@ package puppetmasterless import ( "github.com/mitchellh/packer/packer" + "io/ioutil" + "os" "testing" ) func testConfig() map[string]interface{} { + tf, err := ioutil.TempFile("", "packer") + if err != nil { + panic(err) + } + return map[string]interface{}{ - // "inline": []interface{}{"foo", "bar"}, + "manifest_file": tf.Name(), } } @@ -18,3 +25,61 @@ func TestProvisioner_Impl(t *testing.T) { t.Fatalf("must be a Provisioner") } } + +func TestProvisionerPrepare_manifestFile(t *testing.T) { + config := testConfig() + + delete(config, "manifest_file") + p := new(Provisioner) + err := p.Prepare(config) + if err == nil { + t.Fatal("should be an error") + } + + // Test with a good one + tf, err := ioutil.TempFile("", "packer") + if err != nil { + t.Fatalf("error tempfile: %s", err) + } + defer os.Remove(tf.Name()) + + config["manifest_file"] = tf.Name() + p = new(Provisioner) + err = p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } +} + +func TestProvisionerPrepare_modulePaths(t *testing.T) { + config := testConfig() + + delete(config, "module_paths") + p := new(Provisioner) + err := p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } + + // Test with bad paths + config["module_paths"] = []string{"i-should-not-exist"} + p = new(Provisioner) + err = p.Prepare(config) + if err == nil { + t.Fatal("should be an error") + } + + // Test with a good one + td, err := ioutil.TempDir("", "packer") + if err != nil { + t.Fatalf("error: %s", err) + } + defer os.RemoveAll(td) + + config["module_paths"] = []string{td} + p = new(Provisioner) + err = p.Prepare(config) + if err != nil { + t.Fatalf("err: %s", err) + } +}