[test-improver] Improve tests for tracing package#7740
Conversation
Add three new tests to provider_internal_test.go (package tracing): - TestGenerateRandomSpanID: verifies the happy path produces a valid non-zero 8-byte span ID and that successive calls yield distinct values. - TestGenerateRandomSpanID_Error: injects a failing crypto/rand.Reader to cover the error return path (previously at 83.3%). - TestParentContext_RandomSpanIDFailure: triggers the genErr != nil branch in ParentContext by breaking the random source, verifying the original context is returned unchanged (previously uncovered). Coverage improvements for internal/tracing: generateRandomSpanID: 83.3% → 100% ParentContext: 92.6% → 100% package total: 95.2% → 96.2% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR expands unit test coverage in internal/tracing by adding targeted tests for previously unexercised error paths in span ID generation and ParentContext, improving confidence in tracing initialization behavior.
Changes:
- Added a happy-path test for
generateRandomSpanIDto validate non-zero output. - Added an error-path test for
generateRandomSpanIDby injecting a failing random source. - Added an error-path test for
ParentContextto confirm it returns the original context when span ID generation fails.
Show a summary per file
| File | Description |
|---|---|
| internal/tracing/provider_internal_test.go | Adds tests to cover generateRandomSpanID and ParentContext error branches via injected rand.Reader failures. |
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: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot fix the failing ci checks https://github.com/github/gh-aw-mcpg/actions/runs/27800176294/job/82268593878?pr=7740 |
Fixed in the latest commit. The |
Test Improvements:
provider_internal_test.goFile Analyzed
internal/tracing/provider_internal_test.gointernal/tracingImprovements Made
1. Increased Coverage
TestGenerateRandomSpanID: verifies the happy path — produces a valid non-zero 8-byte span ID and that successive calls yield distinct valuesTestGenerateRandomSpanID_Error: injects a failingcrypto/rand.Readerto cover the previously dead error-return path ingenerateRandomSpanIDTestParentContext_RandomSpanIDFailure: triggers thegenErr != nilbranch inParentContext(lines 322–325 ofprovider.go) by breaking the random source, verifying the original context is returned unchangedgenerateRandomSpanIDParentContext2. Better Testing Patterns
errorReaderstruct (same pattern asauth/header_test.go) to test unreachable crypto-failure branchesrand.Readermutation) are explicitly left non-parallel with a comment explaining whyrequire.NoError/require.Errorfor blocking assertions,assert.*for non-blocking checks — consistent with project conventionst.Parallel()on the pure happy-path test that has no global side effectsTest Execution
All tests pass:
Why These Changes?
provider_internal_test.gowas a thin 52-line file that only testedmergeOTLPHeaders. The two functions with coverage gaps —generateRandomSpanID(83.3%) andParentContext(92.6%) — had unreachable error paths that requirecrypto/randfailure injection. Since the test file is in packagetracing(nottracing_test), it has direct access to the unexportedgenerateRandomSpanIDand can inject therand.Readerfailure needed to exercise both error branches. The improvements follow the exact sameerrorReader/rand.Readerswap pattern already established ininternal/auth/header_test.go.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.