test: add unit tests for version-check comparison and skip logic#1339
test: add unit tests for version-check comparison and skip logic#1339Montana wants to merge 1 commit into
Conversation
|
Hi @burmudar, You're right. I'd added the comparison and skip helpers but never invoked them, so the check was dead code. Fixed by calling Behavior matches the PR description: fail-open on any error, 3s timeout, stderr only so One thing to flag, because this runs before flag parsing, I've reopened another 2 PR's that should address this, you can fold them together if you want. Cheers, |
Before running a command, src does a best-effort check of the running version against the version recommended by the configured instance (/.api/src-cli/version) and prints a single stderr warning when behind. Fail-open, 3s timeout, stderr only so --json is unaffected. Skips version/help/no-arg, dev builds, and SRC_SKIP_VERSION_CHECK. Compares major/minor/patch only. Adds unit tests. Closes sourcegraph#930. Supersedes sourcegraph#1339, sourcegraph#1343.
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.