[test-improver] Improve tests for tracing package#6502
Conversation
Add tests for parseOTLPHeadersWithDecoder with decodeValues=true, covering: - Valid percent-encoded header values (e.g. Bearer%20token → Bearer token) - Invalid percent-encoding fallback to raw value (e.g. %ZZ stays as %ZZ) - Lone percent sign (invalid) fallback to raw value Also add TestResolveHeaders_EnvVar_InvalidPercentEncoding to verify the same fallback behaviour when OTEL_EXPORTER_OTLP_HEADERS contains invalid percent-encoding. Coverage for parseOTLPHeadersWithDecoder improves from 95.2% → 100%, and overall tracing package coverage improves from 96.6% → 97.3%. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot resolve the merge conflicts in this pull request |
…-parse-headers-coverage-1c42a33ee1f5fa0b # Conflicts: # internal/tracing/parse_headers_test.go
Resolved the merge conflict in |
There was a problem hiding this comment.
Pull request overview
This PR improves test coverage for the internal/tracing header parsing logic, specifically exercising the decodeValues=true path used when reading OTLP export headers from OTEL_EXPORTER_OTLP_HEADERS.
Changes:
- Replaces separate percent-encoding tests with a single table-driven
TestParseOTLPHeadersWithDecoder_DecodeValuesthat covers valid decoding and invalid percent-encoding fallback behavior. - Adds an end-to-end test
TestResolveHeaders_EnvVar_InvalidPercentEncodingto verify invalid percent-encoding fallback viaresolveHeaderswhen headers come from the environment.
Show a summary per file
| File | Description |
|---|---|
internal/tracing/parse_headers_test.go |
Adds/reshapes tests to cover decodeValues=true behavior and invalid percent-encoding fallback both directly and through resolveHeaders. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
Test Improvements:
parse_headers_test.goFile Analyzed
internal/tracing/parse_headers_test.gointernal/tracingImprovements Made
1. Increased Coverage
✅ Added
TestParseOTLPHeadersWithDecoder_DecodeValues— directly exercisesparseOTLPHeadersWithDecoderwithdecodeValues=true, including the previously-uncoveredurl.PathUnescapeerror path (invalid percent-encoding such as%ZZor lone%falls back to the raw value)✅ Added
TestResolveHeaders_EnvVar_InvalidPercentEncoding— verifies the same fallback behaviour end-to-end viaresolveHeaderswhenOTEL_EXPORTER_OTLP_HEADERScontains invalid percent-encodingPrevious Coverage: 96.6% (
parseOTLPHeadersWithDecoderat 95.2%)New Coverage: 97.3% (
parseOTLPHeadersWithDecoderat 100%)Improvement: +0.7% overall;
parseOTLPHeadersWithDecoderfully covered2. Better Testing Patterns
assert/requirefrom testify, consistent with existing testsnamefieldTest Execution
All tests pass:
Why These Changes?
parseOTLPHeadersWithDecoderis called withdecodeValues=truewhen OTLP export headers come from theOTEL_EXPORTER_OTLP_HEADERSenvironment variable (W3C Baggage format). The function gracefully falls back to the raw string whenurl.PathUnescapefails, but this error path was never exercised by tests. The new tests confirm this defensive behaviour works correctly.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests