Skip to content

test(encoding): add direct unit tests for sink encodings - #37

Open
Donemmanuelo wants to merge 1 commit into
onelrian:mainfrom
Donemmanuelo:test/sink-encoding-units
Open

test(encoding): add direct unit tests for sink encodings#37
Donemmanuelo wants to merge 1 commit into
onelrian:mainfrom
Donemmanuelo:test/sink-encoding-units

Conversation

@Donemmanuelo

Copy link
Copy Markdown

Closes #33.

User-facing impact

No behavior change. The encoding layer — RFC 3164/5424 framing, the Loki
push-request builder, timestamp-to-nanosecond conversion, and header
parsing — previously had no direct tests, only happy-path coverage through
mock sink tests. These 13 unit tests pin the wire formats, label-set
grouping, account_id defaulting, fallback robustness, and the
cross-transport validation errors, so regressions now fail fast.

Verification

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, and
    cargo test --locked all pass (41 tests).
  • The tested functions were widened to pub(crate) so the existing single
    test module can exercise them; no public API changes.

Note for the maintainer: this branch and #35 both make
timestamp_to_nanoseconds pub(crate). Whichever PR merges second may
need a trivial conflict resolution on that line. This PR's timestamp test
asserts the robustness contract only (numeric fallback); the exact
epoch-zero value is pinned in #35.

Covers the framing and shaping logic that previously had no direct
coverage: RFC 3164 and RFC 5424 frame structure, Loki stream grouping
by label set with nanosecond timestamps, account_id defaulting,
timestamp parsing/fallback robustness, header parsing edge cases,
encoding name round-trips, and the cross-transport validation errors.
The targeted functions are exposed as pub(crate) so the existing single
test module can exercise them directly.
Comment thread src/tests.rs
fn test_timestamp_to_nanoseconds_handles_unparseable_input() {
// Robustness contract: a malformed timestamp must not panic or fail the
// whole batch encode; it resolves to a numeric fallback. The exact
// fallback value is pinned by a test in #35.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment cites "a test in #35" but there's no PR #35 in this repo - and #38 (open) changes this exact fallback to epoch 0. Drop the stale reference or point at the real test. As written, "all digits" passes under either fallback, so it doesn't actually pin anything.

Comment thread src/sinks/encoding.rs
}

fn timestamp_to_nanoseconds(timestamp: &str) -> String {
pub(crate) fn timestamp_to_nanoseconds(timestamp: &str) -> String {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stacking note: #37, #38 and #39 all touch timestamp_to_nanoseconds / tests.rs / process_cycle (same author, all open). They'll conflict on merge - merge in a defined order (#37 -> #38 -> #39) or stack them as one branch. Also, no CI checks are reported on this fork branch; make sure the test gate actually runs before merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add direct unit tests for sink encodings

2 participants