makeStream wires a buffered chunk channel to a FakeConn and returns (stream, sendFn, closeFn). The caller pushes Chunks via sendFn; the parser under test reads them via stream. closeFn closes the channel to signal EOF to the parser.
(t *testing.T, dir fakeconn.Direction, buf int)
| 38 | // parser under test reads them via stream. closeFn closes the channel |
| 39 | // to signal EOF to the parser. |
| 40 | func makeStream(t *testing.T, dir fakeconn.Direction, buf int) ( |
| 41 | *fakeconn.FakeConn, |
| 42 | func(b []byte, readAt, writtenAt time.Time), |
| 43 | func(), |
| 44 | ) { |
| 45 | t.Helper() |
| 46 | ch := make(chan fakeconn.Chunk, buf) |
| 47 | local := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 1} |
| 48 | remote := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 2} |
| 49 | stream := fakeconn.New(ch, local, remote) |
| 50 | var seq uint64 |
| 51 | send := func(b []byte, readAt, writtenAt time.Time) { |
| 52 | seq++ |
| 53 | ch <- fakeconn.Chunk{ |
| 54 | Dir: dir, |
| 55 | Bytes: append([]byte(nil), b...), |
| 56 | ReadAt: readAt, |
| 57 | WrittenAt: writtenAt, |
| 58 | SeqNo: seq, |
| 59 | } |
| 60 | } |
| 61 | closed := false |
| 62 | closer := func() { |
| 63 | if closed { |
| 64 | return |
| 65 | } |
| 66 | closed = true |
| 67 | close(ch) |
| 68 | } |
| 69 | t.Cleanup(func() { |
| 70 | closer() |
| 71 | _ = stream.Close() |
| 72 | }) |
| 73 | return stream, send, closer |
| 74 | } |
| 75 | |
| 76 | // newTestSession constructs a *supervisor.Session wired to fresh |
| 77 | // ClientStream/DestStream and a mocks channel. The session is ready |
no test coverage detected