Problem to solve
The trickiest logic in the codebase — format_rfc3164, format_rfc5424,
build_loki_push_request, timestamp_to_nanoseconds in src/sinks/encoding.rs
and parse_headers in src/config.rs — has no direct unit tests. It is only
exercised indirectly through happy-path sink tests (a 200/204 mock), so framing
errors, label-set regressions, and fallback paths would ship unnoticed.
Proposed outcome
Direct unit tests covering:
- RFC 3164 and RFC 5424 frame structure: PRI, timestamp passthrough, tag/APP-NAME,
JSON MSG part, framing newline
- Loki push request shape: per-label-set stream grouping,
account_id default
to unknown, nanosecond timestamps, log-line JSON
timestamp_to_nanoseconds: RFC3339 with Z, with offset, and the unparseable
fallback path
parse_headers: happy path, whitespace trimming, missing-colon errors, empty
entries
- Cross-transport validation errors (syslog encoding on http transport and
vice versa)
Problem to solve
The trickiest logic in the codebase —
format_rfc3164,format_rfc5424,build_loki_push_request,timestamp_to_nanosecondsinsrc/sinks/encoding.rsand
parse_headersinsrc/config.rs— has no direct unit tests. It is onlyexercised indirectly through happy-path sink tests (a 200/204 mock), so framing
errors, label-set regressions, and fallback paths would ship unnoticed.
Proposed outcome
Direct unit tests covering:
JSON MSG part, framing newline
account_iddefaultto
unknown, nanosecond timestamps, log-line JSONtimestamp_to_nanoseconds: RFC3339 withZ, with offset, and the unparseablefallback path
parse_headers: happy path, whitespace trimming, missing-colon errors, emptyentries
vice versa)