TestReadFileRefusesNonRegular: read_file on a FIFO would block forever in open(2) waiting for a writer, leaking the tool goroutine past Ctrl+C (which cancels the turn but cannot unblock the read); an endless device file would grow the buffer without bound. The Stat guard must refuse without opening.
(t *testing.T)
| 35 | // If the guard is missing, this test hangs rather than fails - the timeout is |
| 36 | // the assertion. |
| 37 | func TestReadFileRefusesNonRegular(t *testing.T) { |
| 38 | path := mkfifo(t) |
| 39 | done := make(chan string, 1) |
| 40 | go func() { done <- ReadFile(path) }() |
| 41 | select { |
| 42 | case got := <-done: |
| 43 | if !strings.Contains(got, "not a regular file") { |
| 44 | t.Fatalf("want a not-a-regular-file refusal, got %q", got) |
| 45 | } |
| 46 | case <-timeoutC(t): |
| 47 | t.Fatal("ReadFile blocked on the FIFO instead of refusing") |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | // TestWriteFileRefusesNonRegular: write_file to an existing FIFO with no |
| 52 | // reader blocks identically in open(2) O_WRONLY; same guard, same contract. |