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

Function TestRequestID

coderd/httpmw/requestid_test.go:16–35  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestRequestID(t *testing.T) {
17 t.Parallel()
18
19 rtr := chi.NewRouter()
20 rtr.Use(httpmw.AttachRequestID)
21 rtr.Get("/", func(w http.ResponseWriter, r *http.Request) {
22 rid := httpmw.RequestID(r)
23 w.WriteHeader(http.StatusOK)
24 w.Write([]byte(rid.String()))
25 })
26 r := httptest.NewRequest("GET", "/", nil)
27 rw := httptest.NewRecorder()
28 rtr.ServeHTTP(rw, r)
29
30 res := rw.Result()
31 defer res.Body.Close()
32 require.Equal(t, http.StatusOK, res.StatusCode)
33 require.NotEmpty(t, res.Header.Get("X-Coder-Request-ID"))
34 require.NotEmpty(t, rw.Body.Bytes())
35}
36
37func TestRequestIDHelpers(t *testing.T) {
38 t.Parallel()

Callers

nothing calls this directly

Calls 11

RequestIDFunction · 0.92
NotEmptyMethod · 0.80
GetMethod · 0.65
WriteMethod · 0.65
CloseMethod · 0.65
WriteHeaderMethod · 0.45
StringMethod · 0.45
ServeHTTPMethod · 0.45
ResultMethod · 0.45
EqualMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected