(t *testing.T)
| 433 | } |
| 434 | |
| 435 | func 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 | } |
nothing calls this directly
no test coverage detected