[test] Add tests for cmd.registerAllFlags, registerFlagCompletions, and OTLP flag defaults#3694
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
Conversation
… flag defaults Cover previously untested functions in internal/cmd: - getDefaultOTLPEndpoint: env var OTEL_EXPORTER_OTLP_ENDPOINT lookup - getDefaultOTLPServiceName: env var OTEL_SERVICE_NAME with default fallback - registerAllFlags: verifies all flag modules are called and flags registered - registerFlagCompletions: verifies all completion functions and ValidArgsFunction - RegisterFlag: verifies registered functions are invoked by registerAllFlags These tests follow the same table-driven pattern as flags_logging_test.go and flags_difc_test.go for consistent coverage of flag helpers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Apr 13, 2026
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 Coverage Improvement:
cmdflags packageFunction Analyzed
internal/cmdregisterFlagCompletionsregisterAllFlags,RegisterFlag,getDefaultOTLPEndpoint,getDefaultOTLPServiceNameregisterFlagCompletionsregisters 6 flag completions +ValidArgsFunction)Why This Function?
registerFlagCompletionsinflags.gowas completely untested despite being a non-trivial function that configures shell completion behavior for 6 flags (--config,--log-dir,--payload-dir,--env,--guards-mode,--allowonly-min-integrity) plus aValidArgsFunction. Every otherflags_*.gofile in the package had corresponding tests (e.g.,flags_logging_test.go,flags_difc_test.go) butflags.goandflags_tracing.gohad none.Tests Added
internal/cmd/flags_tracing_test.goTestGetDefaultOTLPEndpoint: env varOTEL_EXPORTER_OTLP_ENDPOINTlookup (no env, custom value, empty → disabled, trailing slash)TestGetDefaultOTLPServiceName: env varOTEL_SERVICE_NAMEwithconfig.DefaultTracingServiceNamefallback (5 cases)TestGetDefaultOTLPServiceName_DefaultIsCorrect: guards the"mcp-gateway"constantinternal/cmd/flags_test.goTestRegisterAllFlags: verifies all expected flags are registered (core, logging, tracing, DIFC),flagRegistrarsis populatedTestRegisterFlagCompletions: exercises all 6 flag completion functions andValidArgsFunction:--config→.tomlextension filter--log-dir/--payload-dir→ directory filter--env→.envextension filter--guards-mode→{strict, filter, propagate}with no-file-comp--allowonly-min-integrity→{none, unapproved, approved, merged}with no-file-compValidArgsFunction→ active help tip mentioning--configTestRegisterFlag: verifiesRegisterFlagappends toflagRegistrarsand all registrars are invokedTest Pattern
Follows the same table-driven style as
flags_logging_test.goandflags_difc_test.go. Usest.Setenvfor env var isolation andcobra.GetFlagCompletionFunc(available since cobra v1.6.1, project uses v1.10.2) to directly verify completion function registrations.Coverage Report
Generated by Test Coverage Improver
Next run will target the next most complex under-tested function