packer: replace new lines with literal \n
This commit is contained in:
parent
7b4b5d23fc
commit
ba3344a322
|
@ -270,6 +270,7 @@ func (u *MachineReadableUi) Machine(category string, args ...string) {
|
|||
// Prepare the args
|
||||
for i, v := range args {
|
||||
args[i] = strings.Replace(v, ",", "%!(PACKER_COMMA)", -1)
|
||||
args[i] = strings.Replace(args[i], "\n", "\\n", -1)
|
||||
}
|
||||
argsString := strings.Join(args, ",")
|
||||
|
||||
|
|
|
@ -121,28 +121,40 @@ func TestMachineReadableUi(t *testing.T) {
|
|||
buf := new(bytes.Buffer)
|
||||
ui := &MachineReadableUi{Writer: buf}
|
||||
|
||||
// No target
|
||||
ui.Machine("foo", "bar", "baz")
|
||||
data = strings.SplitN(buf.String(), ",", 2)[1]
|
||||
expected = ",foo,bar,baz"
|
||||
expected = ",foo,bar,baz\n"
|
||||
if data != expected {
|
||||
t.Fatalf("bad: %s", data)
|
||||
}
|
||||
|
||||
// Target
|
||||
buf.Reset()
|
||||
ui.Machine("mitchellh,foo", "bar", "baz")
|
||||
data = strings.SplitN(buf.String(), ",", 2)[1]
|
||||
expected = "mitchellh,foo,bar,baz"
|
||||
expected = "mitchellh,foo,bar,baz\n"
|
||||
if data != expected {
|
||||
t.Fatalf("bad: %s", data)
|
||||
}
|
||||
|
||||
// Commas
|
||||
buf.Reset()
|
||||
ui.Machine("foo", "foo,bar")
|
||||
data = strings.SplitN(buf.String(), ",", 2)[1]
|
||||
expected = ",foo,foo%!(PACKER_COMMA)bar"
|
||||
expected = ",foo,foo%!(PACKER_COMMA)bar\n"
|
||||
if data != expected {
|
||||
t.Fatalf("bad: %s", data)
|
||||
}
|
||||
|
||||
// New lines
|
||||
buf.Reset()
|
||||
ui.Machine("foo", "foo\n")
|
||||
data = strings.SplitN(buf.String(), ",", 2)[1]
|
||||
expected = ",foo,foo\\n\n"
|
||||
if data != expected {
|
||||
t.Fatalf("bad: %#v", data)
|
||||
}
|
||||
}
|
||||
|
||||
// This reads the output from the bytes.Buffer in our test object
|
||||
|
|
Loading…
Reference in New Issue