| 82 | } |
| 83 | |
| 84 | func TestReadFrameInvalidTag(t *testing.T) { |
| 85 | t.Parallel() |
| 86 | |
| 87 | // Hand construct a header that indicates a tag we don't know about. We just |
| 88 | // write the header to buf because we expect codec.ReadFrame to bail out when |
| 89 | // reading the invalid tag. |
| 90 | const ( |
| 91 | dataLength uint32 = 10 |
| 92 | bogusTag uint32 = 222 |
| 93 | ) |
| 94 | header := bogusTag<<codec.DataLength | dataLength |
| 95 | data := make([]byte, 4) |
| 96 | binary.BigEndian.PutUint32(data, header) |
| 97 | |
| 98 | var buf bytes.Buffer |
| 99 | _, err := buf.Write(data) |
| 100 | require.NoError(t, err) |
| 101 | |
| 102 | readBuf := make([]byte, 1) |
| 103 | _, _, err = codec.ReadFrame(&buf, readBuf) |
| 104 | require.ErrorIs(t, err, codec.ErrUnsupportedTag) |
| 105 | } |
| 106 | |
| 107 | func TestReadFrameAllocatesWhenNeeded(t *testing.T) { |
| 108 | t.Parallel() |