diff options
| author | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-16 00:53:52 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukas@labunix.xyz> | 2026-09-16 00:53:52 +0200 |
| commit | 9a77de31dc9759708ce9c2d14ea7c0876c214e71 (patch) | |
| tree | 9bd8bab97206468bdd1eed3d77481e37d3fe75e7 /internal/config/load_test.go | |
| parent | 1b39b2683eb820560ba882936d4818af0dcfcec7 (diff) | |
| download | krino-9a77de31dc9759708ce9c2d14ea7c0876c214e71.tar.gz krino-9a77de31dc9759708ce9c2d14ea7c0876c214e71.zip | |
config and engine can load with unsaved text
Diffstat (limited to 'internal/config/load_test.go')
| -rw-r--r-- | internal/config/load_test.go | 27 |
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) + } +} |
