mirror of
https://github.com/lukaszraczylo/semver-generator.git
synced 2026-06-05 22:49:25 +00:00
Fix ignoring strict.force and strict.commit.
This commit is contained in:
@@ -30,57 +30,6 @@ func TestNormalizeVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseVersionParts(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected []int
|
||||
}{
|
||||
{"1.0.0", []int{1, 0, 0}},
|
||||
{"2.1.3", []int{2, 1, 3}},
|
||||
{"1.0", []int{1, 0}},
|
||||
{"10.20.30", []int{10, 20, 30}},
|
||||
{"1.0.0-beta", []int{1, 0, 0}},
|
||||
{"1.0.0-rc1", []int{1, 0, 0}},
|
||||
{"1.0.0+build123", []int{1, 0, 0}},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.input, func(t *testing.T) {
|
||||
result := parseVersionParts(tt.input)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsNewerVersion(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
latest string
|
||||
current string
|
||||
expected bool
|
||||
}{
|
||||
{"major version bump", "2.0.0", "1.0.0", true},
|
||||
{"minor version bump", "1.1.0", "1.0.0", true},
|
||||
{"patch version bump", "1.0.1", "1.0.0", true},
|
||||
{"same version", "1.0.0", "1.0.0", false},
|
||||
{"current is newer major", "1.0.0", "2.0.0", false},
|
||||
{"current is newer minor", "1.0.0", "1.1.0", false},
|
||||
{"current is newer patch", "1.0.0", "1.0.1", false},
|
||||
{"multi-digit versions", "1.10.0", "1.9.0", true},
|
||||
{"longer version is newer", "1.0.1", "1.0", true},
|
||||
{"shorter version is older", "1.0", "1.0.1", false},
|
||||
{"complex comparison", "2.1.3", "2.1.2", true},
|
||||
{"real world example", "0.2.0", "0.1.0", true},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := isNewerVersion(tt.latest, tt.current)
|
||||
assert.Equal(t, tt.expected, result)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindBinaryAsset(t *testing.T) {
|
||||
assets := []ReleaseAsset{
|
||||
{Name: "semver-gen-1.0.0-linux-amd64.tar.gz", BrowserDownloadURL: "https://example.com/linux-amd64.tar.gz"},
|
||||
@@ -102,19 +51,6 @@ func TestFindBinaryAssetEmpty(t *testing.T) {
|
||||
assert.Empty(t, url, "Should return empty string when no assets")
|
||||
}
|
||||
|
||||
func TestUpdateInfo_FormatUpdateMessage(t *testing.T) {
|
||||
info := &UpdateInfo{
|
||||
CurrentVersion: "1.0.0",
|
||||
LatestVersion: "2.0.0",
|
||||
ReleaseURL: "https://github.com/lukaszraczylo/semver-generator/releases/tag/v2.0.0",
|
||||
}
|
||||
|
||||
msg := info.FormatUpdateMessage()
|
||||
assert.Contains(t, msg, "2.0.0")
|
||||
assert.Contains(t, msg, "1.0.0")
|
||||
assert.Contains(t, msg, "https://github.com/lukaszraczylo/semver-generator/releases/tag/v2.0.0")
|
||||
}
|
||||
|
||||
func TestCheckLatestRelease(t *testing.T) {
|
||||
// Initialize logger
|
||||
InitLogger(false)
|
||||
@@ -141,22 +77,6 @@ func TestCheckLatestRelease(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckForUpdate(t *testing.T) {
|
||||
InitLogger(false)
|
||||
|
||||
// Test with a very old version - should show update available if network works
|
||||
info := CheckForUpdate("0.0.1")
|
||||
// This will either return update info or nil depending on network
|
||||
if info != nil {
|
||||
assert.NotEmpty(t, info.LatestVersion)
|
||||
assert.Equal(t, "0.0.1", info.CurrentVersion)
|
||||
}
|
||||
|
||||
// Test with a very new version - should not show update
|
||||
info = CheckForUpdate("999.999.999")
|
||||
assert.Nil(t, info, "Should not show update for future version")
|
||||
}
|
||||
|
||||
func TestFetchLatestReleaseError(t *testing.T) {
|
||||
InitLogger(false)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user