aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/cache_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 15:16:55 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 15:16:55 +0200
commit0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe (patch)
tree358e331945b8206ed4a72703e3aedfe8ea7cdcdb /cmd/krino/cache_test.go
parent1d3f2d1e4c59867024470d3444e12698b7ebb22e (diff)
downloadkrino-0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe.tar.gz
krino-0b5d0eb92c5be2f0ddb2fa73990f31e5654e57fe.zip
krino: 0.0.5 — keyword cache, t and d in reviewv0.0.5
Diffstat (limited to 'cmd/krino/cache_test.go')
-rw-r--r--cmd/krino/cache_test.go47
1 files changed, 47 insertions, 0 deletions
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)
+ }
+}