diff --git a/backend/internal/web/reception/captured/rw.go b/backend/internal/web/reception/captured/rw.go index acb1a28f..7da6c4bc 100644 --- a/backend/internal/web/reception/captured/rw.go +++ b/backend/internal/web/reception/captured/rw.go @@ -44,8 +44,8 @@ func (rw ResponseWriter) Status() (int, bool) { } func (rw ResponseWriter) StatusRepresentation() string { - if !rw.written { - return strconv.Itoa(rw.statusCode) + "*" + if rw.statusCode == 0 && rw.written { + return "200*" } return strconv.Itoa(rw.statusCode) } diff --git a/backend/internal/web/reception/captured/rw_test.go b/backend/internal/web/reception/captured/rw_test.go index 8a369c1e..09091812 100644 --- a/backend/internal/web/reception/captured/rw_test.go +++ b/backend/internal/web/reception/captured/rw_test.go @@ -64,3 +64,29 @@ func TestResponseWriter_SizeRepresentation(t *testing.T) { t.Errorf("expected %q got %q", expected, got) } } + +func TestResponseWriter_statusCodeRepresentation(t *testing.T) { + t.Run("untouched", func(t *testing.T) { + w := New(httptest.NewRecorder()) + expected, got := "0", w.StatusRepresentation() + if expected != got { + t.Errorf("expected %q got %q", expected, got) + } + }) + t.Run("implicit", func(t *testing.T) { + w := New(httptest.NewRecorder()) + w.Write([]byte("lorem ipsum dolor sit amet.")) + expected, got := "200*", w.StatusRepresentation() + if expected != got { + t.Errorf("expected %q got %q", expected, got) + } + }) + t.Run("explicit", func(t *testing.T) { + w := New(httptest.NewRecorder()) + w.WriteHeader(200) + expected, got := "200", w.StatusRepresentation() + if expected != got { + t.Errorf("expected %q got %q", expected, got) + } + }) +}