(t *testing.T)
| 162 | } |
| 163 | |
| 164 | func 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 | |
| 203 | func Test_readBodyAsError(t *testing.T) { |
| 204 | t.Parallel() |
nothing calls this directly
no test coverage detected