[test-improver] Improve tests for cmd tracing helpers#7951
Conversation
- Add TestLogTracingWarnf to cover the previously untested logTracingWarnf function (was 0% coverage, now 100%) - Replace misleading 'unreachable endpoint falls back to noop' test with an accurate test that documents HTTP OTLP's lazy-connection behavior: the exporter construction succeeds even for unreachable endpoints and the provider is a real SDK (non-noop) instance - Add 'sdk provider shuts down cleanly' subtest to TestShutdownTracingProviderWithTimeout to cover the SDK provider code path (previously only the noop path was tested) - Strengthen assertions: remove conditional 'if warnMsg != ""' guard that silently allowed assertions to be skipped; all assertions are now unconditional Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Improves unit test coverage and correctness for the internal/cmd tracing helpers, including adding direct coverage for logTracingWarnf and adjusting tracing-provider tests to reflect OTLP/HTTP exporter lazy-construction behavior.
Changes:
- Added
TestLogTracingWarnfto cover theWarning:prefix behavior emitted via the standardlogpackage. - Updated the “unreachable endpoint” init-provider test to instead assert SDK provider creation without warnings (reflecting lazy OTLP/HTTP exporter construction).
- Added an SDK-provider shutdown subtest to
TestShutdownTracingProviderWithTimeout.
Show a summary per file
| File | Description |
|---|---|
| internal/cmd/tracing_helpers_test.go | Expands and corrects tests for tracing helper initialization, shutdown, and warning logging. |
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: 2
| } | ||
| require.NotNil(t, provider, "Provider must not be nil") | ||
| assert.False(t, warnCalled, "OTLP exporter construction is lazy; no warning expected") | ||
| assert.True(t, provider.IsEnabled(), "Configured endpoint should produce an SDK (non-noop) provider") |
| provider, err := tracing.InitProvider(context.Background(), &config.TracingConfig{ | ||
| Endpoint: "http://127.0.0.1:14318", | ||
| }) | ||
| require.NoError(t, err) | ||
| require.True(t, provider.IsEnabled(), "Expected a real SDK provider with a configured endpoint") | ||
|
|
||
| var warnCalled bool | ||
| shutdownTracingProviderWithTimeout(provider, func(format string, args ...any) { | ||
| warnCalled = true | ||
| }) | ||
| assert.False(t, warnCalled, "SDK provider with no pending spans should shut down without error") |
|
@copilot address review feedback |
Added |
Test Improvements: tracing_helpers_test.go
File Analyzed
internal/cmd/tracing_helpers_test.gointernal/cmdImprovements Made
1. New Test Coverage
TestLogTracingWarnf— coverslogTracingWarnfwhich had 0% coverage; verifies the function prefixes output with"Warning: "using the standardlogpackage2. Corrected Misleading Test
"unreachable endpoint falls back to noop provider and emits warning"→"configured endpoint creates SDK provider without warning"to accurately reflect OTel HTTP OTLP's lazy-connection behaviorotlptracehttp.New"performs a dial during provider creation" (HTTP OTLP is lazily connected; construction succeeds for any URL)if warnMsg != "" { assert.Contains(...) }guard — this silently allowed the assertion to be skipped on every run; replaced with unconditional assertionsassert.True(t, provider.IsEnabled())— verifies that a configured endpoint produces a real SDK provider (not a noop), which is the correct expectation3. Expanded SDK Provider Coverage
"sdk provider shuts down cleanly"subtest toTestShutdownTracingProviderWithTimeout— the existing test only covered the noop provider path; the new subtest creates a real SDK provider and verifies clean shutdownCoverage Improvement
logTracingWarnfinitTracingProviderWithFallbackshutdownTracingProviderWithTimeoutTest Execution
All tests pass:
Why These Changes?
tracing_helpers_test.gowas selected becauselogTracingWarnfwas at 0% coverage despite being a simple, directly-testable function. The existing "unreachable endpoint" test also contained a subtle bug — the conditional assertionif warnMsg != ""meant the assertion never ran (since HTTP OTLP never fails lazily), so the test passed vacuously. This is a real correctness issue: the test appeared to validate error-fallback behavior but was silently a no-op. The fix removes the conditional and accurately documents the actual behavior.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.