From 291721ca318ab1a20d3da5b1ef0ffdbc36bf08bf Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Wed, 20 May 2020 21:35:00 -0400 Subject: Add test for relative paths in merge datasources Signed-off-by: Dave Henderson --- data/datasource_merge_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'data') diff --git a/data/datasource_merge_test.go b/data/datasource_merge_test.go index b08148d5..a7427154 100644 --- a/data/datasource_merge_test.go +++ b/data/datasource_merge_test.go @@ -2,6 +2,8 @@ package data import ( "net/url" + "os" + "path/filepath" "testing" "github.com/spf13/afero" @@ -28,6 +30,17 @@ func TestReadMerge(t *testing.T) { f, _ = fs.Create("/tmp/textfile.txt") _, _ = f.WriteString(`plain text...`) + wd, _ := os.Getwd() + _ = fs.Mkdir(wd, 0777) + f, _ = fs.Create(filepath.Join(wd, "jsonfile.json")) + _, _ = f.WriteString(jsonContent) + f, _ = fs.Create(filepath.Join(wd, "array.json")) + _, _ = f.WriteString(arrayContent) + f, _ = fs.Create(filepath.Join(wd, "yamlfile.yaml")) + _, _ = f.WriteString(yamlContent) + f, _ = fs.Create(filepath.Join(wd, "textfile.txt")) + _, _ = f.WriteString(`plain text...`) + source := &Source{Alias: "foo", URL: mustParseURL("merge:file:///tmp/jsonfile.json|file:///tmp/yamlfile.yaml")} source.fs = fs d := &Data{ @@ -51,6 +64,11 @@ func TestReadMerge(t *testing.T) { assert.NoError(t, err) assert.Equal(t, mergedContent, string(actual)) + source.URL = mustParseURL("merge:./jsonfile.json|baz") + actual, err = d.readMerge(source) + assert.NoError(t, err) + assert.Equal(t, mergedContent, string(actual)) + source.URL = mustParseURL("merge:file:///tmp/jsonfile.json") _, err = d.readMerge(source) assert.Error(t, err) -- cgit v1.2.3