MCPcopy Index your code
hub / github.com/codehamr/codehamr / TestReadFileRefusesNonRegular

Function TestReadFileRefusesNonRegular

internal/tools/nonregular_unix_test.go:37–49  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

35// If the guard is missing, this test hangs rather than fails - the timeout is
36// the assertion.
37func 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.

Callers

nothing calls this directly

Calls 3

mkfifoFunction · 0.85
ReadFileFunction · 0.85
timeoutCFunction · 0.85

Tested by

no test coverage detected