| 297 | } |
| 298 | |
| 299 | func waitForReady(t *testing.T, r io.Reader) { |
| 300 | t.Helper() |
| 301 | scanner := bufio.NewScanner(r) |
| 302 | done := make(chan bool, 1) |
| 303 | go func() { |
| 304 | for scanner.Scan() { |
| 305 | if scanner.Text() == "READY" { |
| 306 | done <- true |
| 307 | return |
| 308 | } |
| 309 | } |
| 310 | done <- false |
| 311 | }() |
| 312 | select { |
| 313 | case ok := <-done: |
| 314 | require.True(t, ok, "subprocess closed stderr before printing READY") |
| 315 | case <-time.After(5 * time.Second): |
| 316 | t.Fatal("timed out waiting for READY from subprocess") |
| 317 | } |
| 318 | // Drain remaining stderr in the background so the pipe never blocks. |
| 319 | go func() { _, _ = io.Copy(io.Discard, r) }() |
| 320 | } |
| 321 | |
| 322 | // testWriter forwards cobra output to t.Log so it does not leak onto stderr. |
| 323 | type testWriter struct{ t *testing.T } |