MCPcopy
hub / github.com/keploy/keploy / makeStream

Function makeStream

pkg/agent/proxy/integrations/http/recordv2_test.go:40–74  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

38// parser under test reads them via stream. closeFn closes the channel
39// to signal EOF to the parser.
40func 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

Callers 1

newTestSessionFunction · 0.85

Calls 2

NewFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected