src.elv.sh@v0.21.0-dev.0.20240515223629-06979efb9a2a/pkg/sys/eunix/waitforread_test.go (about) 1 //go:build unix 2 3 package eunix 4 5 import ( 6 "io" 7 "testing" 8 9 "src.elv.sh/pkg/must" 10 ) 11 12 func TestWaitForRead(t *testing.T) { 13 r0, w0 := must.Pipe() 14 r1, w1 := must.Pipe() 15 defer closeAll(r0, w0, r1, w1) 16 17 w0.WriteString("x") 18 ready, err := WaitForRead(-1, r0, r1) 19 if err != nil { 20 t.Error("WaitForRead errors:", err) 21 } 22 if !ready[0] { 23 t.Error("Want ready[0]") 24 } 25 if ready[1] { 26 t.Error("Don't want ready[1]") 27 } 28 } 29 30 func closeAll(files ...io.Closer) { 31 for _, file := range files { 32 file.Close() 33 } 34 }