MCPcopy Index your code
hub / github.com/coder/coder / TestMiddlewareAccessLog

Function TestMiddlewareAccessLog

agent/agentchat/log_test.go:19–43  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func 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
45func TestMiddlewareWithoutChatHeader(t *testing.T) {
46 t.Parallel()

Callers

nothing calls this directly

Calls 15

LoggerMethod · 0.95
EntriesMethod · 0.95
NewFakeSinkFunction · 0.92
StatusWriterMiddlewareFunction · 0.92
LoggerFunction · 0.92
MiddlewareFunction · 0.92
mustMarshalJSONFunction · 0.85
fieldsByNameFunction · 0.85
NewMethod · 0.65
SetMethod · 0.65
WriteHeaderMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected