Commit Graph
2 Commits
Author SHA1 Message Date
Raghav RoyandCory Benfield ceb91082fe Add Tests for WebSocketErrorCode Get, Read and Write APIs in ByteBuffer (#3198)
### Motivation

The `write(webSocketErrorCode:)`, `readWebSocketErrorCode()`, and
`getWebSocketErrorCode(at:)` methods in ByteBuffer were not covered by
unit tests
https://github.com/apple/swift-nio/pull/3174#pullrequestreview-2743588010.
Since a peekWebSocketErrorCode() method was recently added, I figured I
should verify both the new peek API and the existing WebSocket error
code APIs behave correctly.

### Modifications

    Added tests for:

        write(webSocketErrorCode:)

        getWebSocketErrorCode(at:)

        readWebSocketErrorCode()

    Tests verify:

        Correct encoding and decoding of WebSocket error codes

        Reader index behavior (no movement for get, movement for read)

        Handling of insufficient bytes

        Consistency between peek-before-read and post-read

### Result
These tests ensure the WebSocket error code APIs in ByteBuffer are
correct, and safe to use.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-14 10:52:25 +00:00
Raghav Roy 8440498328 Add More Peek API Variants for ByteBuffer (#3174)
### Motivation:

Existing get APIs require passing an explicit index and can be misused,
leading to verbose and error-prone code. Adding peek variants that
automatically use the current readerIndex improves safety and clarity.
This aims to address issue #2034 and issue #2736, and is a continuation
of PR #3157

### Modifications:

Introduced peekSlice(), peekLengthPrefixedSlice(), peekData(),
peekUUIDBytes() and peekWebSocketErrorCode().
Added tests for each peek API covering normal, empty and repeated peek
scenarios.

### Result:

Developers can now use nonmutating peek APIs to inspect ByteBuffer
contents without altering the reader index.
2025-04-10 14:44:53 +00:00