diff options
| author | Taras Madan <tarasmadan@google.com> | 2025-07-14 14:03:25 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2025-07-16 06:20:46 +0000 |
| commit | 124ec9cc22064a93e87c29fb9f4fd7dc51f98195 (patch) | |
| tree | 179fd79a6399f7af24d5d0307e5fcf044d42732f /dashboard | |
| parent | 03fcfc4b7385b545a89a3fc62bef4e1ec7532e0d (diff) | |
dashboard/app: date parsing error is a bad request
Diffstat (limited to 'dashboard')
| -rw-r--r-- | dashboard/app/coverage.go | 2 | ||||
| -rw-r--r-- | dashboard/app/coverage_test.go | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/dashboard/app/coverage.go b/dashboard/app/coverage.go index 2c5be838a..4611a7977 100644 --- a/dashboard/app/coverage.go +++ b/dashboard/app/coverage.go @@ -284,7 +284,7 @@ func handleFileCoverage(c context.Context, w http.ResponseWriter, r *http.Reques } targetDate, err := civil.ParseDate(dateToStr) if err != nil { - return fmt.Errorf("civil.ParseDate(%s): %w", dateToStr, err) + return fmt.Errorf("%w: civil.ParseDate(%s): %w", ErrClientBadRequest, dateToStr, err) } tp, err := coveragedb.MakeTimePeriod(targetDate, periodType) if err != nil { diff --git a/dashboard/app/coverage_test.go b/dashboard/app/coverage_test.go index bdd528e43..ff038a21c 100644 --- a/dashboard/app/coverage_test.go +++ b/dashboard/app/coverage_test.go @@ -5,6 +5,8 @@ package main import ( "context" + "errors" + "net/http" "strings" "testing" @@ -22,6 +24,18 @@ func setCoverageDBClient(ctx context.Context, client spannerclient.SpannerClient return context.WithValue(ctx, &keyCoverageDBClient, client) } +func TestFileCoverage_BadRequest(t *testing.T) { + badURL := "/test2/coverage/file?dateto=2025-01-31'&period=month" + + "&commit=c0e75905caf368e19aab585d20151500e750de89&filepath=virt/kvm/kvm_main.c" + c := NewCtx(t) + defer c.Close() + c.setCoverageMocks("test2", nil, nil) + _, err := c.GET(badURL) + var httpErr *HTTPError + assert.True(t, errors.As(err, &httpErr)) + assert.Equal(t, http.StatusBadRequest, httpErr.Code) +} + func TestFileCoverage(t *testing.T) { tests := []struct { name string |
