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.go27
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/config/load_test.go b/internal/config/load_test.go
index 1cc3ac9..13ef9d8 100644
--- a/internal/config/load_test.go
+++ b/internal/config/load_test.go
@@ -115,3 +115,30 @@ func TestLockFile(t *testing.T) {
t.Errorf("LockFile = %q, want %q", got, want)
}
}
+
+// TestLoadWithOverriddenText: LoadWith reads the text the caller supplies
+// instead of a file's own, so an editor can check what it has not saved yet
+// (GUI design ยง1.3); the files on disk are neither read differently nor
+// changed.
+func TestLoadWithOverriddenText(t *testing.T) {
+ h := t.TempDir()
+ t.Setenv("HOME", h)
+ main := filepath.Join(h, "krino.conf")
+ if err := os.MkdirAll(filepath.Join(h, "dirs"), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ 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(rule \"r\" (move \"Out\"))\n")}
+ cfg, errs := LoadWith(main, over)
+ if len(errs) > 0 || len(cfg.Dirs) != 1 || len(cfg.Dirs[0].Rules) != 1 {
+ t.Fatalf("overridden text not used: %v %+v", errs, cfg.Dirs)
+ }
+ if _, errs := LoadWith(main, map[string][]byte{main: []byte("(include \"dl\"")}); len(errs) == 0 {
+ t.Error("a mistake in the overridden main file was not reported")
+ }
+ if cfg, errs := Load(main); len(errs) > 0 || len(cfg.Dirs[0].Rules) != 0 {
+ t.Errorf("the files on disk were read differently: %v %+v", errs, cfg.Dirs)
+ }
+}