provisioner/shell: randomize default script name

This commit is contained in:
Mitchell Hashimoto 2015-06-18 10:38:23 +02:00
parent d9fceaf39d
commit 4463083a60
2 changed files with 4 additions and 4 deletions

View File

@ -9,6 +9,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"math/rand"
"os" "os"
"strings" "strings"
"time" "time"
@ -19,8 +20,6 @@ import (
"github.com/mitchellh/packer/template/interpolate" "github.com/mitchellh/packer/template/interpolate"
) )
const DefaultRemotePath = "/tmp/script.sh"
type Config struct { type Config struct {
common.PackerConfig `mapstructure:",squash"` common.PackerConfig `mapstructure:",squash"`
@ -102,7 +101,8 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
} }
if p.config.RemotePath == "" { if p.config.RemotePath == "" {
p.config.RemotePath = DefaultRemotePath p.config.RemotePath = fmt.Sprintf(
"/tmp/script_%d.sh", rand.Intn(9999))
} }
if p.config.Scripts == nil { if p.config.Scripts == nil {

View File

@ -30,7 +30,7 @@ func TestProvisionerPrepare_Defaults(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
if p.config.RemotePath != DefaultRemotePath { if p.config.RemotePath == "" {
t.Errorf("unexpected remote path: %s", p.config.RemotePath) t.Errorf("unexpected remote path: %s", p.config.RemotePath)
} }
} }