10func TestHTTPRoundTripLogger(t *testing.T) {
11 // Create a test server that returns a 500 error
12 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
13 w.Header().Set("Content-Type", "application/json")
14 w.Header().Set("X-Custom-Header", "test-value")
15 w.WriteHeader(http.StatusInternalServerError)
16 w.Write([]byte(`{"error": "Internal server error", "code": 500}`))
20 // Create HTTP client with logging
21 client := NewHTTPClient()
24 req, err := http.NewRequestWithContext(
28 strings.NewReader(`{"test": "data"}`),
33 req.Header.Set("Content-Type", "application/json")
34 req.Header.Set("Authorization", "Bearer secret-token")
36 resp, err := client.Do(req)
40 defer resp.Body.Close()
43 if resp.StatusCode != http.StatusInternalServerError {
44 t.Errorf("Expected status code 500, got %d", resp.StatusCode)
48func TestFormatHeaders(t *testing.T) {
49 headers := http.Header{
50 "Content-Type": []string{"application/json"},
51 "Authorization": []string{"Bearer secret-token"},
52 "X-API-Key": []string{"api-key-123"},
53 "User-Agent": []string{"test-agent"},
56 formatted := formatHeaders(headers)
58 // Check that sensitive headers are redacted
59 if formatted["Authorization"][0] != "[REDACTED]" {
60 t.Error("Authorization header should be redacted")
62 if formatted["X-API-Key"][0] != "[REDACTED]" {
63 t.Error("X-API-Key header should be redacted")
66 // Check that non-sensitive headers are preserved
67 if formatted["Content-Type"][0] != "application/json" {
68 t.Error("Content-Type header should be preserved")
70 if formatted["User-Agent"][0] != "test-agent" {
71 t.Error("User-Agent header should be preserved")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list