MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / TestCall_Success

Function TestCall_Success

internal/nodehub/hub_test.go:189–220  ·  view source on GitHub ↗

---- 测试:Call 成功 ----

(t *testing.T)

Source from the content-addressed store, hash-verified

187// ---- 测试:Call 成功 ----
188
189func TestCall_Success(t *testing.T) {
190 hub := New(Options{PeerExtractor: mdPeerExtractor})
191 env := newTestEnv(t, hub)
192
193 cc := env.dial(t)
194 mock := startNodeMock(t, cc, "node-1")
195 waitOnline(t, hub, "node-1")
196
197 type req struct{ Foo string }
198 type resp struct{ Echo string }
199
200 mock.handle("hello", func(reqID string, body []byte) (bool, []byte, string) {
201 var r req
202 _ = json.Unmarshal(body, &r)
203 out, _ := json.Marshal(resp{Echo: "hi-" + r.Foo})
204 return true, out, ""
205 })
206
207 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
208 defer cancel()
209 raw, err := hub.Call(ctx, "node-1", "hello", req{Foo: "abc"})
210 if err != nil {
211 t.Fatalf("Call: %v", err)
212 }
213 var got resp
214 if err := json.Unmarshal(raw, &got); err != nil {
215 t.Fatalf("unmarshal: %v", err)
216 }
217 if got.Echo != "hi-abc" {
218 t.Fatalf("unexpected echo: %q", got.Echo)
219 }
220}
221
222// ---- 测试:Call 错误响应 ----
223

Callers

nothing calls this directly

Calls 7

newTestEnvFunction · 0.85
startNodeMockFunction · 0.85
waitOnlineFunction · 0.85
dialMethod · 0.80
NewFunction · 0.70
CallMethod · 0.65
handleMethod · 0.45

Tested by

no test coverage detected