MCPcopy Create free account
hub / github.com/PostHog/duckgres / TestMessageRoundTrip

Function TestMessageRoundTrip

server/protocol_test.go:435–473  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

433}
434
435func TestMessageRoundTrip(t *testing.T) {
436 // Test that we can write a message and read it back
437 testCases := []struct {
438 name string
439 msgType byte
440 data []byte
441 }{
442 {"empty", 'Z', []byte{}},
443 {"single byte", 'T', []byte{42}},
444 {"text", 'Q', []byte("SELECT 1\x00")},
445 {"binary", 'd', []byte{0x00, 0xFF, 0x01, 0xFE}},
446 }
447
448 for _, tc := range testCases {
449 t.Run(tc.name, func(t *testing.T) {
450 var buf bytes.Buffer
451
452 // Write
453 err := wire.WriteMessage(&buf, tc.msgType, tc.data)
454 if err != nil {
455 t.Fatalf("wire.WriteMessage() error = %v", err)
456 }
457
458 // Read
459 msgType, body, err := wire.ReadMessage(&buf)
460 if err != nil {
461 t.Fatalf("wire.ReadMessage() error = %v", err)
462 }
463
464 if msgType != tc.msgType {
465 t.Errorf("msgType = %c, want %c", msgType, tc.msgType)
466 }
467
468 if !bytes.Equal(body, tc.data) {
469 t.Errorf("body = %v, want %v", body, tc.data)
470 }
471 })
472 }
473}

Callers

nothing calls this directly

Calls 4

WriteMessageFunction · 0.92
ReadMessageFunction · 0.92
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected