aboutsummaryrefslogtreecommitdiff
path: root/internal/config/load_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config/load_test.go')
-rw-r--r--internal/config/load_test.go49
1 files changed, 46 insertions, 3 deletions
diff --git a/internal/config/load_test.go b/internal/config/load_test.go
index d522316..5f848af 100644
--- a/internal/config/load_test.go
+++ b/internal/config/load_test.go
@@ -157,9 +157,9 @@ func TestLoadWithReportsAnUnusedOverride(t *testing.T) {
broken := []byte("(path \"/tmp\")\n(rule \"BROKEN\")\n")
// The same file, spelled with a "." segment: the text must still be used.
- uncleaned := filepath.Join(h, "dirs", ".", "dl.conf")
- if _, errs := LoadWith(main, map[string][]byte{uncleaned: broken}); len(errs) == 0 {
- t.Error("an override keyed by an uncleaned path was ignored")
+ uncleaned := filepath.Join(h, "dirs") + "/../dirs/dl.conf"
+ if _, errs := LoadWith(main, map[string][]byte{uncleaned: broken}); !strings.Contains(diagText(errs), "BROKEN") {
+ t.Errorf("an override keyed by an uncleaned path was ignored: %v", errs)
}
// A file this load never reads: say so rather than pass silently.
other := filepath.Join(h, "dirs", "other.conf")
@@ -176,3 +176,46 @@ func diagText(ds []*Diag) string {
}
return b.String()
}
+
+// TestLoadWithOverrideForAnotherIncludedDirectory: checking one directory
+// while holding text for another included one is normal for an editor, and
+// not an error; only text for a file no configuration file names is
+// reported (plan 13 review F4 follow-up).
+func TestLoadWithOverrideForAnotherIncludedDirectory(t *testing.T) {
+ h := t.TempDir()
+ t.Setenv("HOME", h)
+ main := filepath.Join(h, "krino.conf")
+ os.MkdirAll(filepath.Join(h, "dirs"), 0o755)
+ os.WriteFile(main, []byte("(include \"a\" \"b\")\n"), 0o644)
+ for _, n := range []string{"a", "b"} {
+ os.WriteFile(filepath.Join(h, "dirs", n+".conf"), []byte("(path \"/tmp\")\n"), 0o644)
+ }
+ bText := []byte("(path \"/tmp\")\n(rule \"r\" (move \"Out\"))\n")
+ if _, errs := LoadWith(main, map[string][]byte{filepath.Join(h, "dirs", "b.conf"): bText}, "a"); len(errs) > 0 {
+ t.Errorf("text for another included directory was reported: %v", errs)
+ }
+ strange := filepath.Join(h, "dirs", "nowhere.conf")
+ if _, errs := LoadWith(main, map[string][]byte{strange: bText}, "a"); len(errs) != 1 {
+ t.Errorf("text for a file no configuration names was not reported: %v", errs)
+ }
+}
+
+// TestLoadWithRefusesCollidingOverrides: two keys that name the same file
+// would leave which text is read to map order, so they are refused (plan 13
+// review F4 follow-up).
+func TestLoadWithRefusesCollidingOverrides(t *testing.T) {
+ h := t.TempDir()
+ t.Setenv("HOME", h)
+ main := filepath.Join(h, "krino.conf")
+ os.MkdirAll(filepath.Join(h, "dirs"), 0o755)
+ os.WriteFile(main, []byte("(include \"dl\")\n"), 0o644)
+ os.WriteFile(filepath.Join(h, "dirs", "dl.conf"), []byte("(path \"/tmp\")\n"), 0o644)
+ over := map[string][]byte{
+ filepath.Join(h, "dirs", "dl.conf"): []byte("(path \"/tmp\")\n"),
+ filepath.Join(h, "dirs") + "/./dl.conf": []byte("(path \"/other\")\n"),
+ }
+ _, errs := LoadWith(main, over)
+ if len(errs) == 0 || !strings.Contains(diagText(errs), "twice") {
+ t.Errorf("colliding override keys were not refused: %v", errs)
+ }
+}