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

Function Test_Client_LogBodiesFalse

codersdk/client_internal_test.go:164–201  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func Test_Client_LogBodiesFalse(t *testing.T) {
165 t.Parallel()
166
167 const method = http.MethodPost
168 const path = "/ok"
169 const reqBody = `{"msg": "request body"}`
170 const resBody = `{"status": "ok"}`
171
172 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
173 w.Header().Set("Content-Type", jsonCT)
174 w.WriteHeader(http.StatusOK)
175 _, _ = io.WriteString(w, resBody)
176 }))
177
178 u, err := url.Parse(s.URL)
179 require.NoError(t, err)
180 client := New(u)
181
182 logBuf := bytes.NewBuffer(nil)
183 client.SetLogger(slog.Make(sloghuman.Sink(logBuf)).Leveled(slog.LevelDebug))
184 client.SetLogBodies(false)
185
186 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
187 defer cancel()
188
189 resp, err := client.Request(ctx, method, path, []byte(reqBody))
190 require.NoError(t, err)
191 defer resp.Body.Close()
192
193 body, err := io.ReadAll(resp.Body)
194 require.NoError(t, err)
195 require.Equal(t, resBody, string(body))
196
197 logStr := logBuf.String()
198 require.Contains(t, logStr, "sdk request")
199 require.Contains(t, logStr, "sdk response")
200 require.NotContains(t, logStr, "body")
201}
202
203func Test_readBodyAsError(t *testing.T) {
204 t.Parallel()

Callers

nothing calls this directly

Calls 14

WriteStringMethod · 0.80
NewFunction · 0.70
SetMethod · 0.65
ParseMethod · 0.65
SetLoggerMethod · 0.65
SetLogBodiesMethod · 0.65
CloseMethod · 0.65
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
RequestMethod · 0.45
ReadAllMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected