Skip to content

test: add unit tests for version-check comparison and skip logic#1339

Closed
Montana wants to merge 1 commit into
sourcegraph:mainfrom
Montana:patch-2
Closed

test: add unit tests for version-check comparison and skip logic#1339
Montana wants to merge 1 commit into
sourcegraph:mainfrom
Montana:patch-2

Conversation

@Montana

@Montana Montana commented Jun 30, 2026

Copy link
Copy Markdown

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 and
deterministically.

isOutdated

Verifies the version comparison that decides whether a warning should fire:

  • Major / minor / patch comparison — confirms an older patch (4.3.0 vs
    4.3.1), older minor (4.3.0 vs 4.4.0), and older major (3.43.0 vs
    4.0.0) are each reported as outdated, while equal (4.4.0 vs 4.4.0) and
    newer (4.5.0 vs 4.4.0) versions are not.
  • v-prefixes — checks that a leading v (v4.3.0) parses correctly and
    compares the same as its bare form, so the result doesn't depend on how the
    version string is formatted.
  • Prereleases — ensures comparison is limited to the major/minor/patch
    components: a prerelease on the same base (4.4.0-rc.1 vs 4.4.0) is not
    flagged as outdated, while a prerelease on an older base (4.3.0-rc.1 vs
    4.4.0) still is. This guards against spurious warnings for users running
    release candidates.
  • Unparseable input — confirms the function returns ok = false (rather
    than guessing) when the current version can't be parsed (dev) or the
    recommended version is empty, so callers know to stay silent instead of
    warning on bad data.

shouldSkipVersionCheck

Verifies the guard that decides when to run the check at all:

  • No-op subcommands — confirms the check is skipped for version, help,
    an empty subcommand, and flag-only invocations like -h / --help, where a
    warning would be noise (and where version already reports this information
    itself).
  • Normal subcommands — confirms the check does run for representative
    real commands (search, batch, api), so the feature isn't accidentally
    disabled.
  • SRC_SKIP_VERSION_CHECK opt-out — confirms setting the environment
    variable suppresses the check, covering the documented escape hatch for CI
    and scripts.
  • Dev builds — confirms the check is skipped when version.BuildTag is the
    default dev value, so local and development builds don't warn on every
    invocation.

Because shouldSkipVersionCheck reads the package-level version.BuildTag, the test temporarily overrides it to a real release value (4.3.0) and restores it via t.Cleanup, keeping the cases isolated from the build-time version.

@burmudar

burmudar commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

@Montana This test should be part of #1338. Please update that PR as I am closing this.

@burmudar burmudar closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants