Skip to content

Commit

Permalink
Merge pull request #850 from hairyhenderson/add-relfile-merge-test
Browse files Browse the repository at this point in the history
Add test for relative paths in merge datasources
  • Loading branch information
Dave Henderson authored and GitHub committed May 21, 2020
2 parents 5e6a077 + 291721c commit be77c65
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions data/datasource_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package data

import (
"net/url"
"os"
"path/filepath"
"testing"

"github.com/spf13/afero"
Expand All @@ -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{
Expand All @@ -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)
Expand Down

0 comments on commit be77c65

Please sign in to comment.