(t *testing.T)
| 184 | } |
| 185 | |
| 186 | func TestWriteMessage(t *testing.T) { |
| 187 | t.Run("write simple message", func(t *testing.T) { |
| 188 | var buf bytes.Buffer |
| 189 | |
| 190 | data := []byte("test data") |
| 191 | err := wire.WriteMessage(&buf, 'T', data) |
| 192 | if err != nil { |
| 193 | t.Fatalf("wire.WriteMessage() error = %v", err) |
| 194 | } |
| 195 | |
| 196 | // Check message type |
| 197 | if buf.Bytes()[0] != 'T' { |
| 198 | t.Errorf("message type = %c, want T", buf.Bytes()[0]) |
| 199 | } |
| 200 | |
| 201 | // Check length (includes itself = 4) |
| 202 | length := binary.BigEndian.Uint32(buf.Bytes()[1:5]) |
| 203 | if length != uint32(len(data)+4) { |
| 204 | t.Errorf("length = %d, want %d", length, len(data)+4) |
| 205 | } |
| 206 | |
| 207 | // Check data |
| 208 | if !bytes.Equal(buf.Bytes()[5:], data) { |
| 209 | t.Errorf("data = %v, want %v", buf.Bytes()[5:], data) |
| 210 | } |
| 211 | }) |
| 212 | |
| 213 | t.Run("write empty message", func(t *testing.T) { |
| 214 | var buf bytes.Buffer |
| 215 | |
| 216 | err := wire.WriteMessage(&buf, 'Z', []byte{}) |
| 217 | if err != nil { |
| 218 | t.Fatalf("wire.WriteMessage() error = %v", err) |
| 219 | } |
| 220 | |
| 221 | // Total should be 5 bytes: type (1) + length (4) |
| 222 | if buf.Len() != 5 { |
| 223 | t.Errorf("buffer length = %d, want 5", buf.Len()) |
| 224 | } |
| 225 | |
| 226 | // Length should be 4 (just the length field itself) |
| 227 | length := binary.BigEndian.Uint32(buf.Bytes()[1:5]) |
| 228 | if length != 4 { |
| 229 | t.Errorf("length = %d, want 4", length) |
| 230 | } |
| 231 | }) |
| 232 | } |
| 233 | |
| 234 | func TestWriteAuthOK(t *testing.T) { |
| 235 | var buf bytes.Buffer |
nothing calls this directly
no test coverage detected