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

Function setupTestMux

internal/serverapi/users_test.go:19–40  ·  view source on GitHub ↗

setupTestMux 创建带 mock 节点的测试 mux,返回 mux 和 ibStore。 nodeHandler 按 RPC 方法名(如 "Restart"、"Status")注册响应。

(t *testing.T, nodeHandlers map[string]func(body any) (json.RawMessage, error))

Source from the content-addressed store, hash-verified

17// setupTestMux 创建带 mock 节点的测试 mux,返回 mux 和 ibStore。
18// nodeHandler 按 RPC 方法名(如 "Restart"、"Status")注册响应。
19func setupTestMux(t *testing.T, nodeHandlers map[string]func(body any) (json.RawMessage, error)) (*http.ServeMux, *inbounds.MemoryStore) {
20 t.Helper()
21
22 hub := &fakeHub{handlers: nodeHandlers}
23
24 nodeStore := nodes.NewMemoryStore()
25 _, _ = nodeStore.Upsert(nodes.Node{
26 ID: "node-1",
27 Name: "node 1",
28 BaseURL: "http://node.test",
29 })
30
31 baseAPI := New(nodeStore)
32 baseAPI.clientFactory = fakeHubClientFactory(hub)
33
34 ibStore := inbounds.NewMemoryStore()
35 userAPI := newUserAPI(users.NewMemoryStore(), nodeStore, ibStore, nil, baseAPI, nil, jobs.ApplyOptions{}, nil)
36 mux := http.NewServeMux()
37 userAPI.Register(mux)
38
39 return mux, ibStore
40}
41
42// createUser 辅助:POST /v1/users,返回 user ID。
43func createUser(t *testing.T, mux *http.ServeMux, body string) string {

Calls 8

UpsertMethod · 0.95
NewMemoryStoreFunction · 0.92
NewMemoryStoreFunction · 0.92
NewMemoryStoreFunction · 0.92
fakeHubClientFactoryFunction · 0.85
newUserAPIFunction · 0.85
NewFunction · 0.70
RegisterMethod · 0.45

Tested by

no test coverage detected