-
Notifications
You must be signed in to change notification settings - Fork 0
Add Hotline codec fixtures and tests for wireframe_testing #487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
109456b
feat(wireframe_testing): add codec fixtures for Hotline protocol testing
leynos 146f0de
refactor(codec-fixtures): introduce typed wrappers and helper functions
leynos 4b33d12
test(codec_fixtures): refactor frame transaction ID checks into helpe…
leynos fc6a653
refactor(tests,codec-fixtures): consolidate codec fixture decoding logic
leynos a366bbd
refactor(codec-fixtures, wireframe-testing): generalize fixture helpe…
leynos 622f828
docs(codec_fixtures): update codec_fixtures docs for API and error ha…
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
582 changes: 582 additions & 0 deletions
582
docs/execplans/9-7-2-codec-fixtures-in-wireframe-testing.md
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| //! Integration tests for the codec fixture functions in `wireframe_testing`. | ||
| //! | ||
| //! These tests verify that each fixture category produces wire bytes with the | ||
| //! expected decoding behaviour when used with `HotlineFrameCodec`. | ||
| #![cfg(not(loom))] | ||
|
|
||
| use std::io; | ||
|
|
||
| use wireframe::codec::examples::HotlineFrameCodec; | ||
| use wireframe_testing::{ | ||
| correlated_hotline_wire, | ||
| decode_frames_with_codec, | ||
| mismatched_total_size_wire, | ||
| oversized_hotline_wire, | ||
| sequential_hotline_wire, | ||
| truncated_hotline_header, | ||
| truncated_hotline_payload, | ||
| valid_hotline_frame, | ||
| valid_hotline_wire, | ||
| }; | ||
|
|
||
| fn hotline_codec() -> HotlineFrameCodec { HotlineFrameCodec::new(4096) } | ||
|
|
||
| /// Decode `wire` with a fresh `HotlineFrameCodec` and verify that decoding | ||
| /// fails with an error message containing `expected_error_substring`. | ||
| fn assert_decode_fails_with(wire: Vec<u8>, expected_error_substring: &str) -> io::Result<()> { | ||
| let codec = hotline_codec(); | ||
| let result = decode_frames_with_codec(&codec, wire); | ||
|
|
||
| let err = result | ||
| .err() | ||
| .ok_or_else(|| io::Error::other("expected decode to fail but it succeeded"))?; | ||
| if !err.to_string().contains(expected_error_substring) { | ||
| return Err(io::Error::other(format!( | ||
| "expected error containing '{expected_error_substring}', got: {err}" | ||
| ))); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| /// Assert that `frames` contains exactly `expected` elements. | ||
| fn assert_frame_count( | ||
| frames: &[wireframe::codec::examples::HotlineFrame], | ||
| expected: usize, | ||
| ) -> io::Result<()> { | ||
| if frames.len() != expected { | ||
| return Err(io::Error::other(format!( | ||
| "expected {expected} frame(s), got {}", | ||
| frames.len() | ||
| ))); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| // ── Valid frame fixtures ──────────────────────────────────────────────── | ||
|
|
||
| #[test] | ||
| fn valid_hotline_wire_decodes_successfully() -> io::Result<()> { | ||
| let wire = valid_hotline_wire(b"hello", 7); | ||
| let codec = hotline_codec(); | ||
| let frames = decode_frames_with_codec(&codec, wire)?; | ||
|
|
||
| assert_frame_count(&frames, 1)?; | ||
|
|
||
| let frame = frames | ||
| .first() | ||
| .ok_or_else(|| io::Error::other("expected one decoded frame"))?; | ||
|
|
||
| if frame.transaction_id != 7 { | ||
| return Err(io::Error::other(format!( | ||
| "expected transaction_id 7, got {}", | ||
| frame.transaction_id | ||
| ))); | ||
| } | ||
| if frame.payload.as_ref() != b"hello" { | ||
| return Err(io::Error::other("payload mismatch")); | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| #[test] | ||
| fn valid_hotline_frame_has_correct_metadata() { | ||
| let frame = valid_hotline_frame(b"data", 42); | ||
| assert_eq!(frame.transaction_id, 42); | ||
| assert_eq!(frame.payload.as_ref(), b"data"); | ||
| } | ||
|
|
||
| // ── Invalid frame fixtures ────────────────────────────────────────────── | ||
|
|
||
| #[test] | ||
| fn oversized_hotline_wire_rejected_by_decoder() -> io::Result<()> { | ||
| let wire = oversized_hotline_wire(4096); | ||
| assert_decode_fails_with(wire, "payload too large") | ||
| } | ||
|
|
||
| #[test] | ||
| fn mismatched_total_size_rejected_by_decoder() -> io::Result<()> { | ||
| let wire = mismatched_total_size_wire(b"test"); | ||
| assert_decode_fails_with(wire, "invalid total size") | ||
| } | ||
|
|
||
| // ── Incomplete frame fixtures ─────────────────────────────────────────── | ||
|
|
||
| #[test] | ||
| fn truncated_header_produces_decode_error() -> io::Result<()> { | ||
| let wire = truncated_hotline_header(); | ||
| assert_decode_fails_with(wire, "bytes remaining") | ||
| } | ||
|
|
||
| #[test] | ||
| fn truncated_payload_produces_decode_error() -> io::Result<()> { | ||
| let wire = truncated_hotline_payload(100); | ||
| assert_decode_fails_with(wire, "bytes remaining") | ||
| } | ||
|
|
||
| /// Verify each frame carries the expected transaction ID. | ||
| fn assert_transaction_ids( | ||
| frames: &[wireframe::codec::examples::HotlineFrame], | ||
| expected_ids: &[u32], | ||
| ) -> io::Result<()> { | ||
| assert_frame_count(frames, expected_ids.len())?; | ||
| for (i, (frame, expected_id)) in frames.iter().zip(expected_ids.iter()).enumerate() { | ||
| if frame.transaction_id != *expected_id { | ||
| return Err(io::Error::other(format!( | ||
| "frame {i}: expected transaction_id {expected_id}, got {}", | ||
| frame.transaction_id | ||
| ))); | ||
| } | ||
| } | ||
| Ok(()) | ||
| } | ||
|
|
||
| // ── Correlation metadata fixtures ─────────────────────────────────────── | ||
|
|
||
| #[test] | ||
| fn correlated_frames_share_transaction_id() -> io::Result<()> { | ||
| let wire = correlated_hotline_wire(42, &[b"a", b"b", b"c"]); | ||
| let codec = hotline_codec(); | ||
| let frames = decode_frames_with_codec(&codec, wire)?; | ||
|
|
||
| assert_frame_count(&frames, 3)?; | ||
| assert_transaction_ids(&frames, &[42, 42, 42]) | ||
| } | ||
|
|
||
| #[test] | ||
| fn sequential_frames_have_incrementing_ids() -> io::Result<()> { | ||
| let wire = sequential_hotline_wire(10, &[b"x", b"y", b"z"]); | ||
| let codec = hotline_codec(); | ||
| let frames = decode_frames_with_codec(&codec, wire)?; | ||
|
|
||
| assert_frame_count(&frames, 3)?; | ||
| assert_transaction_ids(&frames, &[10, 11, 12]) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| Feature: Codec test fixtures | ||
| The wireframe_testing crate provides codec fixture functions for | ||
| generating valid and invalid Hotline-framed wire bytes for testing. | ||
|
|
||
| Scenario: Valid fixture decodes to expected payload | ||
| Given a Hotline codec allowing fixtures up to 4096 bytes | ||
| When a valid fixture frame is decoded | ||
| Then the decoded payload matches the fixture input | ||
|
|
||
| Scenario: Oversized fixture is rejected by decoder | ||
| Given a Hotline codec allowing fixtures up to 4096 bytes | ||
| When an oversized fixture frame is decoded | ||
| Then the decoder reports an invalid data error | ||
|
|
||
| Scenario: Truncated fixture produces a decode error | ||
| Given a Hotline codec allowing fixtures up to 4096 bytes | ||
| When a truncated fixture frame is decoded | ||
| Then the decoder reports bytes remaining on stream | ||
|
|
||
| Scenario: Correlated fixtures share the same transaction identifier | ||
| Given a Hotline codec allowing fixtures up to 4096 bytes | ||
| When correlated fixture frames are decoded | ||
| Then all frames have the expected transaction identifier |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.