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")
	}
}

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")
	}
}
