test: add update version and checksum tests

This commit is contained in:
Mathis Maquenne
2026-08-05 11:50:58 +02:00
parent 3fe050ea15
commit 66fda7424a
2 changed files with 108 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
package update
import "testing"
func TestIsNewer(t *testing.T) {
tests := []struct {
current string
latest string
want bool
}{
{"1.0.0", "1.0.1", true},
{"v1.0.0", "v1.1.0", true},
{"1.0.0", "v2.0.0", true},
{"1.0.0", "1.0.0", false},
{"1.1.0", "1.0.0", false},
{" 1.0.0 ", "1.0.1", true},
{"1.0.0", "1.0.1-rc.1", true},
{"1.0.0-rc.1", "1.0.0", true},
{"dev", "1.0.0", false},
{"1.0.0", "not-a-version", false},
{"", "1.0.0", false},
{"1.0.0", "", false},
}
for _, tt := range tests {
if got := IsNewer(tt.current, tt.latest); got != tt.want {
t.Errorf("IsNewer(%q, %q) = %v, want %v", tt.current, tt.latest, got, tt.want)
}
}
}
func TestTrimV(t *testing.T) {
tests := []struct {
in string
want string
}{
{"v1.2.3", "1.2.3"},
{"1.2.3", "1.2.3"},
{" v1.2.3 ", "1.2.3"},
}
for _, tt := range tests {
if got := trimV(tt.in); got != tt.want {
t.Errorf("trimV(%q) = %q, want %q", tt.in, got, tt.want)
}
}
}
func TestCanonical(t *testing.T) {
tests := []struct {
in string
want string
}{
{"1.2.3", "v1.2.3"},
{"v1.2.3", "v1.2.3"},
{"", ""},
{"garbage", ""},
}
for _, tt := range tests {
if got := canonical(tt.in); got != tt.want {
t.Errorf("canonical(%q) = %q, want %q", tt.in, got, tt.want)
}
}
}