171 lines
4.6 KiB
Go
171 lines
4.6 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.8.0", "2.8.0+9") != 0 {
|
|
t.Fatal("expected equal ignoring +build")
|
|
}
|
|
if Compare("2.8.0", "2.8.0.99") != 0 {
|
|
t.Fatal("expected equal ignoring 4th component")
|
|
}
|
|
if Compare("2.8.1", "2.8.0+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/macos/arm64/Navis",
|
|
SHA256: "def",
|
|
OS: "darwin",
|
|
Arch: "arm64",
|
|
},
|
|
"windows-amd64": {
|
|
URL: "https://git.evilfox.cc/windows/Navis.exe",
|
|
SHA256: "win",
|
|
OS: "windows",
|
|
Arch: "amd64",
|
|
},
|
|
},
|
|
}
|
|
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, "windows") || s != "win" {
|
|
t.Fatalf("windows: %v %q %q", ok, u, s)
|
|
}
|
|
_, _, ok = m.AssetFor("linux-amd64")
|
|
if ok {
|
|
t.Fatal("expected missing linux")
|
|
}
|
|
}
|
|
|
|
func TestManifestAssetForNoCrossOS(t *testing.T) {
|
|
// Feed newer for Windows only — Mac must not get the Windows asset.
|
|
m := Manifest{
|
|
Version: "9.9.9",
|
|
URL: "https://git.evilfox.cc/test2/navi/raw/branch/main/dist/navis-release/windows/Navis.exe",
|
|
SHA256: "winhash",
|
|
Platforms: map[string]PlatformAsset{
|
|
"windows-amd64": {
|
|
URL: "https://git.evilfox.cc/test2/navi/raw/branch/main/dist/navis-release/windows/Navis.exe",
|
|
SHA256: "winhash",
|
|
OS: "windows",
|
|
Arch: "amd64",
|
|
},
|
|
},
|
|
}
|
|
_, _, ok := m.AssetFor("darwin-arm64")
|
|
if ok {
|
|
t.Fatal("darwin must not receive windows-only feed")
|
|
}
|
|
_, _, ok = m.AssetFor("darwin-amd64")
|
|
if ok {
|
|
t.Fatal("darwin-amd64 must not receive windows-only feed")
|
|
}
|
|
u, _, ok := m.AssetFor("windows-amd64")
|
|
if !ok || !strings.Contains(u, "windows/Navis.exe") {
|
|
t.Fatalf("windows should still resolve: %v %q", ok, u)
|
|
}
|
|
}
|
|
|
|
func TestManifestAssetForDarwinUniversalFallback(t *testing.T) {
|
|
m := Manifest{
|
|
Platforms: map[string]PlatformAsset{
|
|
"darwin-universal": {
|
|
URL: "https://git.evilfox.cc/macos/universal/Navis",
|
|
SHA256: "uni",
|
|
OS: "darwin",
|
|
Arch: "universal",
|
|
},
|
|
},
|
|
}
|
|
u, s, ok := m.AssetFor("darwin-arm64")
|
|
if !ok || s != "uni" || !strings.Contains(u, "universal") {
|
|
t.Fatalf("expected universal fallback: %v %q %q", ok, u, s)
|
|
}
|
|
u, s, ok = m.AssetFor("darwin-amd64")
|
|
if !ok || s != "uni" {
|
|
t.Fatalf("expected universal fallback amd64: %v %q %q", ok, u, s)
|
|
}
|
|
}
|
|
|
|
func TestManifestAssetForRejectsCrossOSURL(t *testing.T) {
|
|
m := Manifest{
|
|
Platforms: map[string]PlatformAsset{
|
|
"darwin-arm64": {
|
|
// Mis-labeled: Windows exe under darwin key.
|
|
URL: "https://git.evilfox.cc/windows/Navis.exe",
|
|
OS: "darwin",
|
|
Arch: "arm64",
|
|
},
|
|
"windows-amd64": {
|
|
URL: "https://git.evilfox.cc/macos/arm64/Navis",
|
|
OS: "windows",
|
|
Arch: "amd64",
|
|
},
|
|
},
|
|
}
|
|
if _, _, ok := m.AssetFor("darwin-arm64"); ok {
|
|
t.Fatal("darwin must reject .exe URL")
|
|
}
|
|
if _, _, ok := m.AssetFor("windows-amd64"); ok {
|
|
t.Fatal("windows must reject macos path")
|
|
}
|
|
}
|
|
|
|
func TestManifestAssetForLegacyWindowsOnly(t *testing.T) {
|
|
m := Manifest{
|
|
URL: "https://git.evilfox.cc/dist/navis-release/windows/Navis.exe",
|
|
SHA256: "leg",
|
|
}
|
|
u, s, ok := m.AssetFor("windows-amd64")
|
|
if !ok || s != "leg" || !strings.Contains(u, "Navis.exe") {
|
|
t.Fatalf("legacy windows: %v %q %q", ok, u, s)
|
|
}
|
|
if _, _, ok := m.AssetFor("darwin-arm64"); ok {
|
|
t.Fatal("legacy URL must not apply to darwin")
|
|
}
|
|
}
|
|
|
|
func TestURLLooksLikePlatform(t *testing.T) {
|
|
if !urlLooksLikePlatform("https://x/windows/Navis.exe", "windows") {
|
|
t.Fatal("windows exe ok")
|
|
}
|
|
if urlLooksLikePlatform("https://x/macos/arm64/Navis", "windows") {
|
|
t.Fatal("macos path not for windows")
|
|
}
|
|
if !urlLooksLikePlatform("https://x/macos/arm64/Navis", "darwin") {
|
|
t.Fatal("macos path ok for darwin")
|
|
}
|
|
if urlLooksLikePlatform("https://x/windows/Navis.exe", "darwin") {
|
|
t.Fatal("exe not for darwin")
|
|
}
|
|
if !urlLooksLikePlatform("https://x/android/Navis.apk", "android") {
|
|
t.Fatal("apk ok for android")
|
|
}
|
|
}
|