|
|
|
|
@ -3,6 +3,8 @@ package shell_local
|
|
|
|
|
import (
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
|
|
|
|
"runtime"
|
|
|
|
|
"strings"
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
|
@ -45,8 +47,11 @@ func TestPostProcessorPrepare_InlineShebang(t *testing.T) {
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if p.config.InlineShebang != "/bin/sh -e" {
|
|
|
|
|
expected := ""
|
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
|
expected = "/bin/sh -e"
|
|
|
|
|
}
|
|
|
|
|
if p.config.InlineShebang != expected {
|
|
|
|
|
t.Fatalf("bad value: %s", p.config.InlineShebang)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -101,6 +106,48 @@ func TestPostProcessorPrepare_Script(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPostProcessorPrepare_ExecuteCommand(t *testing.T) {
|
|
|
|
|
// Check that passing a string will work (Backwards Compatibility)
|
|
|
|
|
p := new(PostProcessor)
|
|
|
|
|
raws := testConfig()
|
|
|
|
|
raws["execute_command"] = "foo bar"
|
|
|
|
|
err := p.Configure(raws)
|
|
|
|
|
expected := []string{"sh", "-c", "foo bar"}
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should handle backwards compatibility: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if strings.Compare(strings.Join(p.config.ExecuteCommand, " "), strings.Join(expected, " ")) != 0 {
|
|
|
|
|
t.Fatalf("Did not get expected execute_command: expected: %#v; received %#v", expected, p.config.ExecuteCommand)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that passing a list will work
|
|
|
|
|
p = new(PostProcessor)
|
|
|
|
|
raws = testConfig()
|
|
|
|
|
raws["execute_command"] = []string{"foo", "bar"}
|
|
|
|
|
err = p.Configure(raws)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("should handle backwards compatibility: %s", err)
|
|
|
|
|
}
|
|
|
|
|
expected = []string{"foo", "bar"}
|
|
|
|
|
if strings.Compare(strings.Join(p.config.ExecuteCommand, " "), strings.Join(expected, " ")) != 0 {
|
|
|
|
|
t.Fatalf("Did not get expected execute_command: expected: %#v; received %#v", expected, p.config.ExecuteCommand)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check that default is as expected
|
|
|
|
|
raws = testConfig()
|
|
|
|
|
delete(raws, "execute_command")
|
|
|
|
|
p = new(PostProcessor)
|
|
|
|
|
p.Configure(raws)
|
|
|
|
|
if runtime.GOOS != "windows" {
|
|
|
|
|
expected = []string{"sh", "-c", `chmod +x "{{.Script}}"; {{.Vars}} "{{.Script}}"`}
|
|
|
|
|
} else {
|
|
|
|
|
expected = []string{"cmd", "/C", "{{.Vars}}", "{{.Script}}"}
|
|
|
|
|
}
|
|
|
|
|
if strings.Compare(strings.Join(p.config.ExecuteCommand, " "), strings.Join(expected, " ")) != 0 {
|
|
|
|
|
t.Fatalf("Did not get expected default: expected: %#v; received %#v", expected, p.config.ExecuteCommand)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPostProcessorPrepare_ScriptAndInline(t *testing.T) {
|
|
|
|
|
var p PostProcessor
|
|
|
|
|
raws := testConfig()
|
|
|
|
|
@ -112,7 +159,7 @@ func TestPostProcessorPrepare_ScriptAndInline(t *testing.T) {
|
|
|
|
|
delete(raws, "scripts")
|
|
|
|
|
err := p.Configure(raws)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatalf("should error when no scripts/inline commands are provided: %#v", raws)
|
|
|
|
|
t.Fatalf("should error when no scripts/inline commands are provided")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test with both
|
|
|
|
|
|