From c9eb790ecfbce688bc94b00ee112469331a75914 Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Sat, 6 Apr 2019 13:06:25 -0400 Subject: [PATCH] Handle multi-document YAML streams Signed-off-by: Dave Henderson --- data/data_test.go | 2 +- tests/integration/datasources_file_test.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/data/data_test.go b/data/data_test.go index 63c95a16d..b4abdf9d3 100644 --- a/data/data_test.go +++ b/data/data_test.go @@ -56,7 +56,7 @@ func TestUnmarshalArray(t *testing.T) { assert.EqualValues(t, expected, actual) } test(JSONArray(`["foo","bar",{"baz":{"qux": true},"quux":{"42":18},"corge":{"false":"blah"}}]`)) - test(YAMLArray(` + test(YAMLArray(`--- - foo - bar - baz: diff --git a/tests/integration/datasources_file_test.go b/tests/integration/datasources_file_test.go index 6966393e0..ba14c08d8 100644 --- a/tests/integration/datasources_file_test.go +++ b/tests/integration/datasources_file_test.go @@ -38,6 +38,14 @@ FOO.BAR = "values can be double-quoted, and shell\nescapes are supported" BAZ = "variable expansion: ${FOO}" QUX='single quotes ignore $variables' +`, + "multidoc.yaml": `--- +# empty document +--- +foo: bar +--- +foo: baz +... `, }), fs.WithDir("sortorder", fs.WithFiles(map[string]string{ @@ -185,4 +193,12 @@ bar`}) "FOO.BAR": "values can be double-quoted, and shell\nescapes are supported", "QUX": "single quotes ignore $variables" }`}) + + result = icmd.RunCmd(icmd.Command(GomplateBin, + "-c=multidoc.yaml", + "-i", `{{ .multidoc.foo }}`, + ), func(c *icmd.Cmd) { + c.Dir = s.tmpDir.Path() + }) + result.Assert(c, icmd.Expected{ExitCode: 0, Out: "bar"}) }