diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-03 23:45:25 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-03 23:45:25 +0200 |
| commit | 626bbc46f9debf892ee250cd104fd37371f2e41e (patch) | |
| tree | 03efcbd6c2baa04e9b07e52a64b7b7374ec91855 /internal/cli/work_test.go | |
| parent | 7e6b2e4c2ba957899b12dac7e0ea9f7c29a9a7b3 (diff) | |
cli: harden report import error handling
Capture deferred close errors and preserve parse failure context in import date parsing.
Diffstat (limited to 'internal/cli/work_test.go')
| -rw-r--r-- | internal/cli/work_test.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/cli/work_test.go b/internal/cli/work_test.go index 9621bfb..2be0231 100644 --- a/internal/cli/work_test.go +++ b/internal/cli/work_test.go @@ -7,6 +7,7 @@ import ( "strconv" "strings" "testing" + "time" timrTimer "codeberg.org/snonux/timr/internal/timer" ) @@ -108,6 +109,28 @@ func TestWorkLoginLogoutWithTimerFlags(t *testing.T) { } } +func TestParseImportDateFallbackLayout(t *testing.T) { + parsed, err := parseImportDate("06.01.2026") + if err != nil { + t.Fatalf("parseImportDate() error = %v", err) + } + + expected := time.Date(2026, 1, 6, 0, 0, 0, 0, time.Local) + if parsed.Year() != expected.Year() || parsed.Month() != expected.Month() || parsed.Day() != expected.Day() { + t.Fatalf("parsed date = %v, want %v", parsed, expected) + } +} + +func TestParseImportDateIncludesUnderlyingParseError(t *testing.T) { + _, err := parseImportDate("not-a-date") + if err == nil { + t.Fatal("parseImportDate() error = nil, want error") + } + if !strings.Contains(err.Error(), "unsupported import date") { + t.Fatalf("parseImportDate() error = %v, want unsupported import date context", err) + } +} + func writeWorkConfig(t *testing.T, dbDir, host string) string { return writeWorkConfigWithAuto(t, dbDir, host, false) } |
