SyncBuffer is a threadsafe buffer for testing. Some times replace stdout/stderr with a buffer to capture output. stdout and stderr are threadsafe, but a regular bytes.Buffer is not. Using this instead helps prevents race conditions with output.
| 381 | // stdout and stderr are threadsafe, but a regular bytes.Buffer is not. |
| 382 | // Using this instead helps prevents race conditions with output. |
| 383 | type SyncBuffer struct { |
| 384 | buf bytes.Buffer |
| 385 | mu sync.Mutex |
| 386 | } |
| 387 | |
| 388 | func (sb *SyncBuffer) Write(p []byte) (n int, err error) { |
| 389 | sb.mu.Lock() |
nothing calls this directly
no outgoing calls
no test coverage detected