[test-improver] Improve tests for version package#4140
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test-improver] Improve tests for version package#4140github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Add TestBuildVersionString with 8 subtests covering all explicit-parameter branches of BuildVersionString. Coverage of the function rises from 0% to 68%, and overall package coverage rises from 12% to 72%. The remaining uncovered lines are the debug.ReadBuildInfo() fallback paths (vcs.revision and vcs.time settings) which are only populated when the binary is built with embedded VCS metadata and cannot be exercised in unit tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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:
version_test.goFile Analyzed
internal/version/version_test.gointernal/versionImprovements Made
1. Increased Coverage
TestBuildVersionStringwith 8 subtests covering all explicit-parameter branches ofBuildVersionStringSetandGetwere tested;BuildVersionStringhad 0%)2. Better Testing Patterns
t.Runsubtests for each logical scenario inTestBuildVersionStringassert.Equalfor deterministic cases (all three parameters supplied)strings.HasPrefix/strings.HasSuffix/assert.Containsfor partially-deterministic cases where thedebug.ReadBuildInfo()fallback may or may not append extra fieldsrequire.GreaterOrEqualto guard against panics when splitting output into parts3. Branches Covered
mainVersion != ""→ use mainVersionmainVersion == ""→ use"dev"gitCommit != ""→ use"commit: <gitCommit>"gitCommit == ""→ fall back todebug.ReadBuildInfo()vcs.revisionbuildDate != ""→ use"built: <buildDate>"buildDate == ""→ fall back todebug.ReadBuildInfo()vcs.timegitCommitis not truncated (truncation only in fallback)The remaining uncovered lines (~32% of
BuildVersionString) are the loop bodies that matchvcs.revision/vcs.timesettings insidedebug.ReadBuildInfo(); these are only populated when the binary is built with embedded VCS metadata viago build -ldflagsand cannot be exercised in unit tests.Test Execution
All tests pass:
Why These Changes?
BuildVersionStringconstructs the version string displayed in health checks,--versionoutput, and MCP client metadata. It had zero test coverage despite having six distinct branches. The new tests document the function's contract for all explicitly-supplied-parameter paths and confirm stability across builds wheredebug.ReadBuildInfo()may or may not provide VCS metadata.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests