test: add unit tests for version-check comparison and skip logic#1339
Closed
Montana wants to merge 1 commit into
Closed
test: add unit tests for version-check comparison and skip logic#1339Montana wants to merge 1 commit into
Montana wants to merge 1 commit into
Conversation
Contributor
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.
Hey Sourcegraph,
This change adds
cmd/src/version_check_test.go, covering both pieces of thenew logic with table-driven unit tests. The functions under test are pure and have no network or filesystem dependencies, so the suite runs fast anddeterministically.
isOutdatedVerifies the version comparison that decides whether a warning should fire:
4.3.0vs4.3.1), older minor (4.3.0vs4.4.0), and older major (3.43.0vs4.0.0) are each reported as outdated, while equal (4.4.0vs4.4.0) andnewer (
4.5.0vs4.4.0) versions are not.v-prefixes — checks that a leadingv(v4.3.0) parses correctly andcompares the same as its bare form, so the result doesn't depend on how the
version string is formatted.
components: a prerelease on the same base (
4.4.0-rc.1vs4.4.0) is notflagged as outdated, while a prerelease on an older base (
4.3.0-rc.1vs4.4.0) still is. This guards against spurious warnings for users runningrelease candidates.
ok = false(ratherthan guessing) when the current version can't be parsed (
dev) or therecommended version is empty, so callers know to stay silent instead of
warning on bad data.
shouldSkipVersionCheckVerifies the guard that decides when to run the check at all:
version,help,an empty subcommand, and flag-only invocations like
-h/--help, where awarning would be noise (and where
versionalready reports this informationitself).
real commands (
search,batch,api), so the feature isn't accidentallydisabled.
SRC_SKIP_VERSION_CHECKopt-out — confirms setting the environmentvariable suppresses the check, covering the documented escape hatch for CI
and scripts.
version.BuildTagis thedefault
devvalue, so local and development builds don't warn on everyinvocation.
Because
shouldSkipVersionCheckreads the package-levelversion.BuildTag, the test temporarily overrides it to a real release value (4.3.0) and restores it viat.Cleanup, keeping the cases isolated from the build-time version.