diff options
Diffstat (limited to 'internal/ui/table_test.go')
| -rw-r--r-- | internal/ui/table_test.go | 37 |
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") |
