fakeHub 是单测用的 hub 适配器:把 nodes.Client 的 RPC 方法名映射到 内联 handler,返回预置 JSON 响应。模拟节点行为而无需启动真实节点。 用法: hub := &fakeHub{ handlers: map[string]func(body any) (json.RawMessage, error){ "Usage": func(any) (json.RawMessage, error) { return json.RawMessage(`{"running":true}`), nil }, "
| 20 | // } |
| 21 | // client := nodes.NewClientWithHub("n1", hub) |
| 22 | type fakeHub struct { |
| 23 | handlers map[string]func(body any) (json.RawMessage, error) |
| 24 | } |
| 25 | |
| 26 | func (f *fakeHub) Call(_ context.Context, _ string, method string, body any) (json.RawMessage, error) { |
| 27 | if h, ok := f.handlers[method]; ok { |
nothing calls this directly
no outgoing calls
no test coverage detected