MCPcopy
hub / github.com/keploy/keploy / TestForwardsBothDirections

Function TestForwardsBothDirections

pkg/agent/proxy/relay/relay_test.go:147–192  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

145}
146
147func TestForwardsBothDirections(t *testing.T) {
148 t.Parallel()
149 h := newHarness(t, Config{})
150
151 // Client → Dest.
152 payload := []byte("hello world")
153 go h.writeClient(payload)
154 got := h.readDest(len(payload))
155 if string(got) != string(payload) {
156 t.Fatalf("dest got %q, want %q", got, payload)
157 }
158
159 // Dest → Client.
160 reply := []byte("hi back")
161 go h.writeDest(reply)
162 rec := h.readClient(len(reply))
163 if string(rec) != string(reply) {
164 t.Fatalf("client got %q, want %q", rec, reply)
165 }
166
167 // FakeConns should have received both chunks with correct Dir.
168 c, err := h.r.ClientStream().ReadChunk()
169 if err != nil {
170 t.Fatalf("ClientStream.ReadChunk: %v", err)
171 }
172 if c.Dir != fakeconn.FromClient {
173 t.Fatalf("ClientStream chunk Dir=%v, want FromClient", c.Dir)
174 }
175 if string(c.Bytes) != string(payload) {
176 t.Fatalf("ClientStream chunk bytes=%q, want %q", c.Bytes, payload)
177 }
178 if c.ReadAt.IsZero() || c.WrittenAt.IsZero() {
179 t.Fatalf("ClientStream chunk missing timestamps: %+v", c)
180 }
181
182 d, err := h.r.DestStream().ReadChunk()
183 if err != nil {
184 t.Fatalf("DestStream.ReadChunk: %v", err)
185 }
186 if d.Dir != fakeconn.FromDest {
187 t.Fatalf("DestStream chunk Dir=%v, want FromDest", d.Dir)
188 }
189 if string(d.Bytes) != string(reply) {
190 t.Fatalf("DestStream chunk bytes=%q, want %q", d.Bytes, reply)
191 }
192}
193
194func TestTimestampsStampedAtRealBoundary(t *testing.T) {
195 t.Parallel()

Callers

nothing calls this directly

Calls 9

newHarnessFunction · 0.85
writeClientMethod · 0.80
readDestMethod · 0.80
writeDestMethod · 0.80
readClientMethod · 0.80
ReadChunkMethod · 0.80
ClientStreamMethod · 0.80
IsZeroMethod · 0.80
DestStreamMethod · 0.80

Tested by

no test coverage detected