MCPcopy
hub / github.com/tinode/chat / TestDispatchNoMessage

Function TestDispatchNoMessage

server/session_test.go:1145–1177  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1143}
1144
1145func TestDispatchNoMessage(t *testing.T) {
1146 remoteAddr := "192.168.0.1"
1147 s := &Session{
1148 send: make(chan any, 10),
1149 authLvl: auth.LevelAuth,
1150 ver: 16,
1151 remoteAddr: remoteAddr,
1152 }
1153 wg := sync.WaitGroup{}
1154 r := responses{}
1155 wg.Add(1)
1156 go s.testWriteLoop(&r, &wg)
1157
1158 msg := &ClientComMessage{}
1159
1160 s.dispatch(msg)
1161 close(s.send)
1162 wg.Wait()
1163
1164 if len(r.messages) != 1 {
1165 t.Errorf("responses: expected 1, received %d.", len(r.messages))
1166 }
1167 resp := r.messages[0].(*ServerComMessage)
1168 if resp == nil {
1169 t.Fatal("Response must be ServerComMessage")
1170 }
1171 if resp.Ctrl == nil {
1172 t.Fatal("Response must contain a ctrl message.")
1173 }
1174 if resp.Ctrl.Code != 400 {
1175 t.Errorf("Response code: expected 400, got %d", resp.Ctrl.Code)
1176 }
1177}

Callers

nothing calls this directly

Calls 4

testWriteLoopMethod · 0.95
dispatchMethod · 0.95
WaitMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…