captureSlog redirects slog.Default to a buffer for the duration of a test and returns the buffer + a restore function. Used by the forward-uncached logging tests to assert presence of the request/response log lines that were missing pre-PR (every PUT/POST through the proxy was a black hole).
(t *testing.T)
| 78 | // logging tests to assert presence of the request/response log lines that |
| 79 | // were missing pre-PR (every PUT/POST through the proxy was a black hole). |
| 80 | // |
| 81 | // The buffer must be concurrency-safe: proxy handlers log from goroutines |
| 82 | // that outlive the request (e.g. the CONNECT close logger fires after both |
| 83 | // tunnel legs finish), so test-goroutine String reads would race an |
| 84 | // unsynchronized bytes.Buffer. |
| 85 | func captureSlog(t *testing.T) (*syncBuffer, func()) { |
| 86 | t.Helper() |
| 87 | prev := slog.Default() |
| 88 | buf := &syncBuffer{} |
| 89 | slog.SetDefault(slog.New(slog.NewTextHandler(buf, &slog.HandlerOptions{Level: slog.LevelDebug}))) |
no outgoing calls
no test coverage detected