MCPcopy Create free account
hub / github.com/dank/rlapi / TestPsyNetRPC_SendRequestSync

Function TestPsyNetRPC_SendRequestSync

psynetrpc_test.go:108–146  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

106}
107
108func TestPsyNetRPC_SendRequestSync(t *testing.T) {
109 // Setup mock server
110 mockServer := NewMockWSServer()
111 defer mockServer.Close()
112
113 // Create PsyNet instance and establish connection
114 psyNet := NewPsyNet()
115 rpc, err := psyNet.establishSocket(mockServer.URL(), "test-token", "test-session", "test-player")
116 if err != nil {
117 t.Fatalf("Failed to establish socket: %v", err)
118 }
119
120 go rpc.readMessages()
121 rpc.schedulePing()
122 defer rpc.Close()
123
124 // Setup expected response
125 expectedResponse := &PsyResponse{
126 Result: json.RawMessage(`{"Result":{"shops": [{"id": 1, "name": "test shop"}]}}`),
127 }
128 mockServer.SetResponse("PsyNetMessage_X_0", expectedResponse)
129
130 // Test sync request
131 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
132 defer cancel()
133
134 var result map[string]interface{}
135 err = rpc.sendRequestSync(ctx, "Shops/GetStandardShops", map[string]interface{}{}, &result)
136 if err != nil {
137 t.Fatalf("sendRequestSync failed: %v", err)
138 }
139
140 // Verify result
141 if shops, ok := result["shops"]; !ok {
142 t.Error("Expected 'shops' in response")
143 } else if shopsArray, ok := shops.([]interface{}); !ok || len(shopsArray) != 1 {
144 t.Error("Expected shops array with one item")
145 }
146}
147
148func TestPsyNetRPC_SendRequestAsync(t *testing.T) {
149 // Setup mock server

Callers

nothing calls this directly

Calls 10

CloseMethod · 0.95
establishSocketMethod · 0.95
URLMethod · 0.95
SetResponseMethod · 0.95
NewMockWSServerFunction · 0.85
NewPsyNetFunction · 0.85
readMessagesMethod · 0.80
schedulePingMethod · 0.80
sendRequestSyncMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected