57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package update
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestCompare(t *testing.T) {
|
|
if Compare("1.1.0", "1.0.0") <= 0 {
|
|
t.Fatal("expected newer")
|
|
}
|
|
if Compare("1.0.0", "1.1.0") >= 0 {
|
|
t.Fatal("expected older")
|
|
}
|
|
if Compare("1.1.0", "1.1.0") != 0 {
|
|
t.Fatal("expected equal")
|
|
}
|
|
// Build must not make same product look outdated or newer for update checks.
|
|
if Compare("2.7.2", "2.7.2+9") != 0 {
|
|
t.Fatal("expected equal ignoring +build")
|
|
}
|
|
if Compare("2.7.2", "2.7.2.99") != 0 {
|
|
t.Fatal("expected equal ignoring 4th component")
|
|
}
|
|
if Compare("2.7.3", "2.7.2+1") <= 0 {
|
|
t.Fatal("expected product bump to win")
|
|
}
|
|
if DisplayVersion() == "" || !strings.Contains(DisplayVersion(), "+") {
|
|
t.Fatal("DisplayVersion should include build")
|
|
}
|
|
}
|
|
|
|
func TestManifestAssetFor(t *testing.T) {
|
|
m := Manifest{
|
|
URL: "https://git.evilfox.cc/legacy.exe",
|
|
SHA256: "abc",
|
|
Platforms: map[string]PlatformAsset{
|
|
"darwin-arm64": {
|
|
URL: "https://git.evilfox.cc/arm64/Navis",
|
|
SHA256: "def",
|
|
},
|
|
},
|
|
}
|
|
u, s, ok := m.AssetFor("darwin-arm64")
|
|
if !ok || u == "" || s != "def" {
|
|
t.Fatalf("darwin: %v %q %q", ok, u, s)
|
|
}
|
|
u, s, ok = m.AssetFor("windows-amd64")
|
|
if !ok || !strings.Contains(u, "legacy") || s != "abc" {
|
|
t.Fatalf("windows legacy: %v %q %q", ok, u, s)
|
|
}
|
|
_, _, ok = m.AssetFor("linux-amd64")
|
|
if ok {
|
|
t.Fatal("expected missing linux")
|
|
}
|
|
}
|