(t *testing.T)
| 17 | ) |
| 18 | |
| 19 | func TestMiddlewareAccessLog(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | |
| 22 | chatID := uuid.New() |
| 23 | ancestorID := uuid.New() |
| 24 | sink := testutil.NewFakeSink(t) |
| 25 | handler := tracing.StatusWriterMiddleware(loggermw.Logger(sink.Logger(), nil)( |
| 26 | agentchat.Middleware(http.HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { |
| 27 | rw.WriteHeader(http.StatusNoContent) |
| 28 | })), |
| 29 | )) |
| 30 | |
| 31 | req := httptest.NewRequest(http.MethodGet, "/test", nil) |
| 32 | req.Header.Set(workspacesdk.CoderChatIDHeader, chatID.String()) |
| 33 | req.Header.Set(workspacesdk.CoderAncestorChatIDsHeader, mustMarshalJSON(t, []string{ancestorID.String()})) |
| 34 | rw := httptest.NewRecorder() |
| 35 | handler.ServeHTTP(rw, req) |
| 36 | require.Equal(t, http.StatusNoContent, rw.Code) |
| 37 | |
| 38 | entries := sink.Entries() |
| 39 | require.Len(t, entries, 1) |
| 40 | fields := fieldsByName(entries[0].Fields) |
| 41 | require.Equal(t, chatID.String(), fields["chat_id"]) |
| 42 | require.Equal(t, []string{ancestorID.String()}, fields["ancestor_chat_ids"]) |
| 43 | } |
| 44 | |
| 45 | func TestMiddlewareWithoutChatHeader(t *testing.T) { |
| 46 | t.Parallel() |
nothing calls this directly
no test coverage detected