summaryrefslogtreecommitdiff
path: root/internal/ui/table_test.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-04-08 22:07:25 +0300
committerPaul Buetow <paul@buetow.org>2026-04-08 22:07:25 +0300
commit42226b12e7a172810bf785cef4cbb4fb41e2da3d (patch)
tree96ad6868d4609192ba522a3b10481bb0ab1933c3 /internal/ui/table_test.go
parent595075473a51b2709f1554f055df43a69369cddd (diff)
task a: fix temp-file cleanup on desc write failure
Diffstat (limited to 'internal/ui/table_test.go')
-rw-r--r--internal/ui/table_test.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/internal/ui/table_test.go b/internal/ui/table_test.go
index dccec31..d8c9db4 100644
--- a/internal/ui/table_test.go
+++ b/internal/ui/table_test.go
@@ -200,6 +200,27 @@ func TestHandleDescEditDoneUpdatesDescriptionAndRemovesTempFile(t *testing.T) {
}
}
+func TestPrepareDescriptionTempFileRemovesTempFileOnWriteError(t *testing.T) {
+ tmp := t.TempDir()
+ tempFile := filepath.Join(tmp, "desc.txt")
+ if err := os.WriteFile(tempFile, []byte("stale"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ path, err := prepareDescriptionTempFile("updated description", func() (descriptionTempFile, error) {
+ return &failingDescriptionTempFile{path: tempFile}, nil
+ })
+ if err == nil {
+ t.Fatalf("prepareDescriptionTempFile succeeded unexpectedly: %q", path)
+ }
+ if path != "" {
+ t.Fatalf("expected empty path on error, got %q", path)
+ }
+ if _, statErr := os.Stat(tempFile); !os.IsNotExist(statErr) {
+ t.Fatalf("temp file still exists after write error: %v", statErr)
+ }
+}
+
func TestHandleDescEditDoneRemovesTempFileOnEditorError(t *testing.T) {
tmp := t.TempDir()
tempFile := filepath.Join(tmp, "desc.txt")
@@ -228,6 +249,22 @@ func TestHandleDescEditDoneRemovesTempFileOnEditorError(t *testing.T) {
}
}
+type failingDescriptionTempFile struct {
+ path string
+}
+
+func (f *failingDescriptionTempFile) Name() string {
+ return f.path
+}
+
+func (f *failingDescriptionTempFile) WriteString(string) (int, error) {
+ return 0, fmt.Errorf("write failed")
+}
+
+func (f *failingDescriptionTempFile) Close() error {
+ return nil
+}
+
func TestHandleFilterModeReportsReloadError(t *testing.T) {
tmp := t.TempDir()
taskPath := filepath.Join(tmp, "task")