// 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) } }