test(semver): upgrade semver_precise_test.go to testify + expand coverage - #48960
Conversation
…ases, TestIsNewer table Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates CLI semantic-version tests to use Testify and broaden parsing and comparison coverage for issue #48958.
Changes:
- Migrates assertions to
assertandrequire. - Adds invalid, pre-release, comparison, and equivalent-version cases.
- Documents test scope.
Show a summary per file
| File | Description |
|---|---|
pkg/cli/semver_precise_test.go |
Expands and refactors semantic-version tests. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Medium
| name: "pre-release suffix - precise", | ||
| version: "v1.2.3-rc.1", | ||
| expected: true, |
There was a problem hiding this comment.
Fixed in the same commit. Removed the duplicate TestIsNewer table from semver_precise_test.go and migrated TestVersionIsNewer in semver_test.go to use require/assert from testify, consolidating the migration into the existing (more complete) test.
| func TestIsNewer(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| v1 string | ||
| v2 string | ||
| newer bool |
There was a problem hiding this comment.
Fixed in commit fix(semver): count only core-version dots.... IsPreciseVersion now strips pre-release and build-metadata suffixes before counting dots, so only the core version components are evaluated. Added v1.2-rc.1 as a wantNil: true boundary case — since golang.org/x/mod/semver rejects a pre-release on a sub-three-part base, parseVersion returns nil, confirming an imprecise core with a dotted suffix is never misclassified as precise.
|
@copilot please run the Unresolved review threads:
|
… duplicate TestIsNewer; migrate TestVersionIsNewer to testify Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
|
🎉 This pull request is included in a new release. Release: |
pkg/cli/semver_precise_test.gowas the only test file inpkg/clinot usingtestify, and had gaps in coverage forIsNewer, invalid inputs, and pre-release versions.Changes
if/t.Errorf/t.Fatalfwithrequire/assert;require.NotNilnow short-circuits subtests on parse failure instead of manual nil-check +Fatalf"not-a-version"and""cases toTestIsPreciseVersionusingrequire.Nilto assertparseVersionreturns nilv1.2.3-rc.1case confirming it is treated as precise (dotCount >= 2on Raw)TestIsNewertable — new test covering newer/older major, minor, patch, and equal versions in both directionsTestPreciseVersionPreference— refactored from a single hardcodedv6/v6.0.0scenario to a table with three equivalent-version pairs (v6,v6.0,6.1)pkg/cliparseVersionwrapper, not fullsemverutillogic