[test-improver] Improve tests for version.BuildVersionString#8386
Draft
github-actions[bot] wants to merge 1 commit into
Draft
[test-improver] Improve tests for version.BuildVersionString#8386github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
Add tests for the two branches in BuildVersionString where empty gitCommit or buildDate fall back to debug.ReadBuildInfo(). These branches were previously uncovered (lines 92-94, 100-102). To enable injection without API changes, extract debug.ReadBuildInfo into a package-level var readBuildInfo. Tests override this var to supply deterministic mock build info, covering: - vcs.revision used when gitCommit is empty - vcs.time used when buildDate is empty - both fields used when both are empty - build info unavailable (ok=false) - build info available but no vcs settings Coverage: BuildVersionString 89.5% → 100%, package 95.1% → 100% 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.
File analyzed
internal/version/version_test.go(and productioninternal/version/version.go)Problem
BuildVersionStringhad two uncovered branches — the inner bodies executed whendebug.ReadBuildInfo()returns a non-emptyvcs.revision(lines 92–94) orvcs.time(lines 100–102). These are the "auto-detect from binary build info" fallback paths that run when the caller passes emptygitCommitorbuildDate.Changes
internal/version/version.goExtracted
debug.ReadBuildInfointo a package-level variable:BuildVersionStringnow callsreadBuildInfo()instead ofdebug.ReadBuildInfo()directly. This is a zero-cost indirection — the variable holds the exact same function pointer at runtime, but allows tests to inject a deterministic replacement without any API changes.internal/version/version_test.goAdded
TestBuildVersionString_FallbackFromBuildInfowith five subtests that overridereadBuildInfoand restore it viat.Cleanup:Coverage
BuildVersionStringTest output
All existing tests continue to pass.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.