From 0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Mon, 14 Sep 2026 15:16:55 +0200 Subject: krino: 0.0.5 — keyword cache, t and d in review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/krino/cache_test.go | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 cmd/krino/cache_test.go (limited to 'cmd/krino/cache_test.go') diff --git a/cmd/krino/cache_test.go b/cmd/krino/cache_test.go new file mode 100644 index 0000000..65526b3 --- /dev/null +++ b/cmd/krino/cache_test.go @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package main + +import ( + "os" + "path/filepath" + "strings" + "testing" + "time" +) + +// TestRunWritesKeywordCache: a dry run over a directory with a content rule +// leaves a private cache under ~/.cache/krino, and check says where it is. +func TestRunWritesKeywordCache(t *testing.T) { + h := home(t) + dl := filepath.Join(h, "dl") + os.MkdirAll(dl, 0o755) + p := filepath.Join(dl, "a.txt") + os.WriteFile(p, []byte("invoice from acme ltd"), 0o644) + old := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC) + os.Chtimes(p, old, old) + if code, _, errOut := runCLI(t, "init"); code != 0 { + t.Fatal(errOut) + } + if code, _, errOut := runCLI(t, "new", "dl", dl); code != 0 { + t.Fatal(errOut) + } + rules := "(path \"~/dl\")\n(rule \"acme\" (when (content \"acme ltd\")) (move \"Acme\"))\n" + os.WriteFile(filepath.Join(h, ".config", "krino", "dirs", "dl.conf"), []byte(rules), 0o644) + + for i := 0; i < 2; i++ { + if code, out, errOut := runCLI(t, "-n"); code != 0 || !strings.Contains(out, "a.txt") { + t.Fatalf("run %d: exit %d\n%s\n%s", i, code, out, errOut) + } + } + fi, err := os.Stat(filepath.Join(h, ".cache", "krino", "dl.cache")) + if err != nil { + t.Fatal(err) + } + if fi.Mode().Perm() != 0o600 { + t.Errorf("cache mode %o, want 600", fi.Mode().Perm()) + } + if _, out, _ := runCLI(t, "check"); !strings.Contains(out, "cache: ~/.cache/krino\n") { + t.Errorf("check does not show the cache directory:\n%s", out) + } +} -- cgit v1.3