diff --git a/loader/loader.go b/loader/loader.go index 0c0efecbfe..d686b192b3 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -152,7 +152,7 @@ func all(paths []string, f func(*Result, string) error) (*Result, error) { } if info.IsDir() { - loadDirRecursive(&errors, path, loaded.withParent(info.Name())) + loadDirRecursive(&errors, path, loaded) } else { err := f(loaded, path) if err != nil { diff --git a/loader/loader_test.go b/loader/loader_test.go index 1de4c860a9..9a29edf207 100644 --- a/loader/loader_test.go +++ b/loader/loader_test.go @@ -108,7 +108,7 @@ func TestLoadGuessYAML(t *testing.T) { func TestLoadDirRecursive(t *testing.T) { files := map[string]string{ - "/a/data1.json": `[1,2,3]`, + "/a/data1.json": `{"a": [1,2,3]}`, "/a/e.rego": `package q`, "/b/data2.yaml": `{"aaa": {"bbb": 1}}`, "/b/data3.yaml": `{"aaa": {"ccc": 2}}`, @@ -127,13 +127,11 @@ func TestLoadDirRecursive(t *testing.T) { { "zzz": "b", "a": [1,2,3], - "b": { - "aaa": { - "bbb": 1, - "ccc": 2 - }, - "d": null - } + "aaa": { + "bbb": 1, + "ccc": 2 + }, + "d": null } `) if !reflect.DeepEqual(loaded.Documents, expectedDocuments) { @@ -154,9 +152,9 @@ func TestLoadDirRecursive(t *testing.T) { func TestLoadRooted(t *testing.T) { files := map[string]string{ - "/foo.json": "[1,2,3]", - "/bar.yaml": "abc", - "/baz/qux.json": "null", + "/foo.json": "[1,2,3]", + "/bar/bar.yaml": "abc", + "/baz/qux/qux.json": "null", } test.WithTempFS(files, func(rootDir string) { @@ -170,7 +168,7 @@ func TestLoadRooted(t *testing.T) { t.Fatalf("Unexpected error: %v", err) } expected := parseJSON(` - {"four": [1,2,3], "one": {"two": "abc"}, "three": {"baz": null}} + {"four": [1,2,3], "one": {"two": "abc"}, "three": {"qux": null}} `) if !reflect.DeepEqual(loaded.Documents, expected) { t.Fatalf("Expected %v but got: %v", expected, loaded.Documents) diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index 12b0935e49..26c1aa09c3 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -159,7 +159,7 @@ func TestRuntimeProcessWatchEvents(t *testing.T) { } t0 := time.Now() - path := storage.MustParsePath("/" + path.Base(rootDir) + "/some") + path := storage.MustParsePath("/some") // In practice, reload takes ~100us on development machine. maxWaitTime := time.Second * 1