[test-improver] Improve tests for config tracing package#5076
Merged
Conversation
- Add GetSampleRate tests for nil receiver and nil SampleRate (100% coverage, was 66.7%) - Add GetSampleRate test for explicit zero rate - Add tests for init-registered DefaultsSetter (nil Gateway, nil Tracing, already-set ServiceName) - Add tests for init-registered StdinConverter (full field mapping, default ServiceName, nil Gateway, nil OpenTelemetry) - init function coverage improved from 53.8% to 92.3% - config_tracing.go overall coverage: GetSampleRate 100% (was 66.7%), init 92.3% (was 53.8%) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR expands unit test coverage for the internal/config tracing configuration feature, focusing on nil-safety and stdin (JSON) conversion behavior around OpenTelemetry tracing settings.
Changes:
- Adds
GetSampleRatecoverage for nil receiver / nilSampleRate/ explicit0.0cases. - Adds coverage for tracing defaults behavior, including preserving an explicitly-set
ServiceName. - Adds coverage for the init-registered stdin converter mapping and its early-return paths.
Show a summary per file
| File | Description |
|---|---|
internal/config/config_tracing_test.go |
Adds targeted tests for tracing sample-rate behavior, default application, and stdin converter field mapping / nil-safety. |
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
Comment on lines
+326
to
+331
| // TestTracingDefaults_NilGateway verifies that applyDefaults does not panic when | ||
| // cfg.Gateway is nil (tracing is not configured). | ||
| func TestTracingDefaults_NilGateway(t *testing.T) { | ||
| cfg := &Config{} | ||
| require.NotPanics(t, func() { applyDefaults(cfg) }, | ||
| "applyDefaults must not panic when Gateway is nil") |
Comment on lines
+281
to
+287
| // TestGetSampleRate_NilReceiver verifies that calling GetSampleRate on a nil | ||
| // *TracingConfig returns the default sample rate rather than panicking. | ||
| func TestGetSampleRate_NilReceiver(t *testing.T) { | ||
| var cfg *TracingConfig | ||
| assert.InDelta(t, DefaultTracingSampleRate, cfg.GetSampleRate(), 0.001, | ||
| "nil receiver must return DefaultTracingSampleRate") | ||
| } |
Collaborator
|
@copilot address the review feedback and fix the ci failures |
…lures Agent-Logs-Url: https://github.com/github/gh-aw-mcpg/sessions/b359d089-d760-4a62-829b-a04cb25e73a8 Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Contributor
Done in c4e578a:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Test Improvements: config_tracing_test.go
File Analyzed
internal/config/config_tracing_test.gointernal/configImprovements Made
1. Increased Coverage
GetSampleRateon nil receiver — prevented panic, returns default (was untested)GetSampleRatewith nilSampleRatefield — returns default (was untested)GetSampleRatewith explicit0.0— distinct from unset, returns 0.0 (was untested)applyDefaultswhencfg.Gatewayis nil — no panic (was untested)applyDefaultswhencfg.Gateway.Tracingis nil — no panic (was untested)applyDefaultswhenServiceNameis already set — preserves custom value (was untested)StdinConverterfull field mapping fromStdinOpenTelemetryConfig→TracingConfigStdinConverterdefaultServiceNameapplied when stdin value is emptyStdinConverterearly-return whenstdinCfg.Gatewayis nilStdinConverterearly-return whenstdinCfg.Gateway.OpenTelemetryis nilPrevious Coverage (config_tracing.go functions):
GetSampleRate: 66.7%init: 53.8%New Coverage:
GetSampleRate: 100.0%init: 92.3%2. Better Testing Patterns
require.NotPanicsused for nil-safety assertionsrequire.NotNilguards before accessing pointer fields in stdin converter testsTestType_ScenarioconventionTest Execution
All new and existing tests pass (pre-existing
TestFetchAndFixSchema_NetworkErrorfailure is unrelated — network-dependent test that fails in CI sandbox):Why These Changes?
config_tracing_test.gohad clear coverage gaps:GetSampleRatewas only tested with a non-nil pointer (missing nil receiver and nil-field cases), and theinit-registered callbacks forDefaultsSetterandStdinConverterhad uncovered early-return paths and the full converter mapping path was untested. These are important paths — nil-safety on a value receiver method and correct behavior of the stdin JSON config pipeline — that could regress silently without tests.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
The following domain was blocked by the firewall during workflow execution:
invalidhostthatdoesnotexist12345.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.