* refactor: 收拢核心管线、强化错误处理、优化热路径与更新体积 * fix: preserve download recovery and bound PBZX decoding Keep VM diagnostics available during plugin initialization failures and verify settings through the unified driver lifecycle.
53 lines
1.5 KiB
Go
53 lines
1.5 KiB
Go
//go:build windows
|
|
|
|
package selfupdate
|
|
|
|
import (
|
|
"os"
|
|
"runtime/debug"
|
|
"testing"
|
|
)
|
|
|
|
func TestTakeoverVersionOrdering(t *testing.T) {
|
|
build := func(stamp string) *debug.BuildInfo {
|
|
return &debug.BuildInfo{Settings: []debug.BuildSetting{{Key: "vcs.time", Value: stamp}}}
|
|
}
|
|
yesterday, today := build("2026-12-03T00:00:00Z"), build("2026-12-04T00:00:00Z")
|
|
for _, tc := range []struct {
|
|
new, old string
|
|
build *debug.BuildInfo
|
|
want bool
|
|
}{
|
|
{"v0.2.14", "v0.2.13", today, true},
|
|
{"v0.2.13", "v0.2.13", today, false},
|
|
{"v0.2.12", "v0.2.13", today, false},
|
|
{"v0.2.14-alpha.2", "v0.2.14-alpha.1", today, true},
|
|
{"v0.2.14-alpha.2", "v0.2.14", today, false},
|
|
{"v0.2.14-dev-111aaaa", "v0.2.14-dev-fff3333", today, true},
|
|
{"v0.2.14-dev-fff3333", "v0.2.14-dev-111aaaa", yesterday, false},
|
|
{"v0.2.14-dev-111aaaa", "v0.2.14-dev-fff3333", build(""), false},
|
|
} {
|
|
if got := isNewerClient(tc.new, tc.build, tc.old, yesterday); got != tc.want {
|
|
t.Errorf("take over with %s over %s = %t, want %t", tc.new, tc.old, got, tc.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestReadPEBuildInfoMatchesRuntime(t *testing.T) {
|
|
exe, err := os.Executable()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
want, ok := debug.ReadBuildInfo()
|
|
if !ok {
|
|
t.Skip("runtime buildinfo unavailable")
|
|
}
|
|
got, err := readPEBuildInfo(exe)
|
|
if err != nil {
|
|
t.Fatalf("readPEBuildInfo(%s): %v", exe, err)
|
|
}
|
|
if got.Main.Path != want.Main.Path || got.GoVersion != want.GoVersion {
|
|
t.Fatalf("readPEBuildInfo = (%q, %q), want (%q, %q)", got.Main.Path, got.GoVersion, want.Main.Path, want.GoVersion)
|
|
}
|
|
}
|