MCPcopy
hub / github.com/daptin/daptin / TestWebSocketCreateDestroyTopic

Function TestWebSocketCreateDestroyTopic

websocket_test.go:365–397  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

363}
364
365func TestWebSocketCreateDestroyTopic(t *testing.T) {
366 ensureServer()
367 token := signUpAndGetToken(t)
368
369 ws := dialWS(t, token)
370 defer ws.Close()
371
372 topicName := fmt.Sprintf("test-topic-%d", time.Now().UnixNano())
373
374 // create topic
375 id := nextReqId()
376 sendJSON(t, ws, wsPayload{
377 Id: id,
378 Method: "create-topicName",
379 Payload: map[string]interface{}{"name": topicName},
380 })
381
382 msg := recvJSON(t, ws, 5*time.Second)
383 if msg.Type != "response" || msg.Ok == nil || !*msg.Ok {
384 t.Errorf("expected successful create response, got type=%q ok=%v error=%q", msg.Type, msg.Ok, msg.Error)
385 }
386
387 // destroy it
388 sendJSON(t, ws, wsPayload{
389 Id: nextReqId(),
390 Method: "destroy-topicName",
391 Payload: map[string]interface{}{"name": topicName},
392 })
393 msg = recvJSON(t, ws, 5*time.Second)
394 if msg.Type != "response" || msg.Ok == nil || !*msg.Ok {
395 t.Errorf("expected successful destroy response, got type=%q ok=%v error=%q", msg.Type, msg.Ok, msg.Error)
396 }
397}
398
399func TestWebSocketDestroySystemTopicError(t *testing.T) {
400 ensureServer()

Callers

nothing calls this directly

Calls 7

ensureServerFunction · 0.85
signUpAndGetTokenFunction · 0.85
dialWSFunction · 0.85
nextReqIdFunction · 0.85
sendJSONFunction · 0.85
recvJSONFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected