aboutsummaryrefslogtreecommitdiff
path: root/cmd/krino/sort_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 23:58:43 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 23:58:43 +0200
commit67ada0b5bc25cb6cff3ab780d82cb0bfe64e4968 (patch)
treee05598d93c71af19be946b3cb0d4e80688596c24 /cmd/krino/sort_test.go
parent04f46bf180cf506ceadb76b5afacf9c02700cc65 (diff)
downloadkrino-67ada0b5bc25cb6cff3ab780d82cb0bfe64e4968.tar.gz
krino-67ada0b5bc25cb6cff3ab780d82cb0bfe64e4968.zip
tests: apply error exits 1 and w stops krino through the real command; undo projection occupied half
Diffstat (limited to 'cmd/krino/sort_test.go')
-rw-r--r--cmd/krino/sort_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/cmd/krino/sort_test.go b/cmd/krino/sort_test.go
index 2a72e6a..22e00b4 100644
--- a/cmd/krino/sort_test.go
+++ b/cmd/krino/sort_test.go
@@ -265,3 +265,71 @@ func TestLaterDirectoryIsNotBlockedByAnEarlierOnesClaims(t *testing.T) {
t.Errorf("cb's x.txt did not move into the place ca's left free: %q, %v\n%s", b, err, out)
}
}
+
+// devFullFixture builds two directories, d1 and d2, each with two files a
+// rule moves, and a log at /dev/full, where every write fails: applying
+// anything is a genuine apply error, not a step failure.
+func devFullFixture(t *testing.T) {
+ t.Helper()
+ if _, err := os.Stat("/dev/full"); err != nil {
+ t.Skip("no /dev/full on this system")
+ }
+ h := home(t)
+ old := time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC)
+ if code, _, errOut := runCLI(t, "init"); code != 0 {
+ t.Fatal(errOut)
+ }
+ for _, n := range []string{"d1", "d2"} {
+ for _, name := range []string{"a.pdf", "b.pdf"} {
+ p := filepath.Join(h, n, name)
+ os.MkdirAll(filepath.Dir(p), 0o755)
+ os.WriteFile(p, []byte(n+name), 0o644)
+ os.Chtimes(p, old, old)
+ }
+ if code, _, errOut := runCLI(t, "new", n, filepath.Join(h, n)); code != 0 {
+ t.Fatal(errOut)
+ }
+ os.WriteFile(filepath.Join(h, ".config", "krino", "dirs", n+".conf"), []byte("(path \"~/"+n+"\")\n(rule \"r\" (move \"Out\"))\n"), 0o644)
+ }
+ f, err := os.OpenFile(filepath.Join(h, ".config", "krino", "krino.conf"), os.O_APPEND|os.O_WRONLY, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ f.WriteString("(log \"/dev/full\")\n")
+ f.Close()
+}
+
+// TestApplyErrorExitsOne: an error applying a directory - here the log
+// cannot be written - makes krino exit 1 (triage 34m: removing that exit
+// code left every test passing).
+func TestApplyErrorExitsOne(t *testing.T) {
+ devFullFixture(t)
+ code, _, errOut := runCLI(t, "-y", "d1")
+ if code != 1 || !strings.Contains(errOut, "no space left") {
+ t.Errorf("exit %d, stderr %q; want 1 and the write error", code, errOut)
+ }
+}
+
+// TestWriteStopsKrinoWhenApplyFails: [w] in review stops krino after its
+// directory even when applying it fails - the next directory is not planned
+// or asked about (review cli F3), driven through the real command with a
+// pipe standing in for the terminal (triage 28m).
+func TestWriteStopsKrinoWhenApplyFails(t *testing.T) {
+ devFullFixture(t)
+ r, w, err := os.Pipe()
+ if err != nil {
+ t.Fatal(err)
+ }
+ w.WriteString("cyw") // choose per file, yes to a.pdf, write before b.pdf
+ w.Close()
+ oldStdin, oldTerm := stdin, stdinIsTerminal
+ stdin, stdinIsTerminal = r, func() bool { return true }
+ t.Cleanup(func() { stdin, stdinIsTerminal = oldStdin, oldTerm })
+ code, out, errOut := runCLI(t, "--no-pager")
+ if code != 1 {
+ t.Errorf("exit %d, want 1\n%s\n%s", code, out, errOut)
+ }
+ if strings.Contains(out, "krino: d2") {
+ t.Errorf("d2 was planned after [w]:\n%s", out)
+ }
+}