diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-04 08:23:10 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-04 08:23:10 +0200 |
| commit | 992a2d5487e5bd033d1ab107478369b2818a2238 (patch) | |
| tree | 9332bebc92394f29063abb1fc4bcfd3dd453ff01 | |
| parent | a499218f4f4c33b18bb821adfdbe8c0c25f8ca91 (diff) | |
tests: add fuzzing for duration and time parsing
| -rw-r--r-- | internal/duration/parse_test.go | 18 | ||||
| -rw-r--r-- | internal/timefmt/parse_test.go | 20 |
2 files changed, 38 insertions, 0 deletions
diff --git a/internal/duration/parse_test.go b/internal/duration/parse_test.go index 048e9b3..d1f1f37 100644 --- a/internal/duration/parse_test.go +++ b/internal/duration/parse_test.go @@ -78,3 +78,21 @@ func TestParseInvalidDurations(t *testing.T) { }) } } + +func FuzzParse(f *testing.F) { + seeds := []string{ + "1h30m", + "3600", + "-60", + "abc", + "", + " ", + } + for _, seed := range seeds { + f.Add(seed) + } + + f.Fuzz(func(t *testing.T, input string) { + _, _ = Parse(input) + }) +} diff --git a/internal/timefmt/parse_test.go b/internal/timefmt/parse_test.go index 6d90bcf..679acfa 100644 --- a/internal/timefmt/parse_test.go +++ b/internal/timefmt/parse_test.go @@ -103,3 +103,23 @@ func TestParseInvalidValues(t *testing.T) { }) } } + +func FuzzParseAt(f *testing.F) { + seeds := []string{ + "today", + "yesterday", + "2024-01-15", + "2024-01-15T09:30", + "1714424400", + "banana", + "", + } + for _, seed := range seeds { + f.Add(seed) + } + + now := time.Date(2026, 3, 3, 12, 0, 0, 0, time.Local) + f.Fuzz(func(t *testing.T, input string) { + _, _ = ParseAt(input, now) + }) +} |
