mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-04-21 17:36:40 +00:00
buildmeta: remove premature Release/PackageMeta structs and ChannelNames slice — keep only the shared vocabulary types. uadetect: replace regex-based matching with token-based matching. Split UA on whitespace/slash/semicolon, match lowercase tokens. Strip xnu kernel info for Rosetta. Single Parse() entry point. httpclient: return plain *http.Client from New(). Make Do() and Get() free functions. Only retry idempotent methods (GET/HEAD).
118 lines
3.0 KiB
Go
118 lines
3.0 KiB
Go
package uadetect_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/webinstall/webi-installers/internal/buildmeta"
|
|
"github.com/webinstall/webi-installers/internal/uadetect"
|
|
)
|
|
|
|
func TestOS(t *testing.T) {
|
|
tests := []struct {
|
|
ua string
|
|
want buildmeta.OS
|
|
}{
|
|
// uname -srm style
|
|
{"Darwin 23.1.0 arm64", buildmeta.OSDarwin},
|
|
{"Darwin 20.2.0 x86_64", buildmeta.OSDarwin},
|
|
{"Linux 6.1.0-18-amd64 x86_64", buildmeta.OSLinux},
|
|
{"Linux 5.15.0 aarch64", buildmeta.OSLinux},
|
|
|
|
// WSL: Linux, not Windows (contains "microsoft" in kernel release)
|
|
{"Linux 5.15.146.1-microsoft-standard-WSL2 x86_64", buildmeta.OSLinux},
|
|
|
|
// Windows
|
|
{"MS AMD64", buildmeta.OSWindows},
|
|
{"PowerShell/7.3.0", buildmeta.OSWindows},
|
|
{"Microsoft Windows 10.0.19045", buildmeta.OSWindows},
|
|
|
|
// Android before Linux
|
|
{"Android 13 aarch64", buildmeta.OSAndroid},
|
|
|
|
// Browser-style
|
|
{"Macintosh; Intel Mac OS X 10_15_7", buildmeta.OSDarwin},
|
|
|
|
// Minimal agents → assume Linux
|
|
{"curl/8.1.2", buildmeta.OSLinux},
|
|
{"wget/1.21", buildmeta.OSLinux},
|
|
|
|
// Explicit unknown
|
|
{"-", ""},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.ua, func(t *testing.T) {
|
|
got := uadetect.Parse(tt.ua).OS
|
|
if got != tt.want {
|
|
t.Errorf("Parse(%q).OS = %q, want %q", tt.ua, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestArch(t *testing.T) {
|
|
tests := []struct {
|
|
ua string
|
|
want buildmeta.Arch
|
|
}{
|
|
{"Darwin 23.1.0 arm64", buildmeta.ArchARM64},
|
|
{"Linux 6.1.0 aarch64", buildmeta.ArchARM64},
|
|
{"Linux 5.4.0 x86_64", buildmeta.ArchAMD64},
|
|
{"MS AMD64", buildmeta.ArchAMD64},
|
|
{"Linux 5.10.0 armv7l", buildmeta.ArchARMv7},
|
|
{"Linux 5.10.0 armv6l", buildmeta.ArchARMv6},
|
|
{"Linux 5.4.0 ppc64le", buildmeta.ArchPPC64LE},
|
|
|
|
// Rosetta: xnu kernel info says ARM64 but actual arch is x86_64
|
|
{"Darwin 20.2.0 Darwin Kernel Version 20.2.0; root:xnu-7195.60.75~1/RELEASE_ARM64_T8101 x86_64", buildmeta.ArchAMD64},
|
|
|
|
{"-", ""},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.ua, func(t *testing.T) {
|
|
got := uadetect.Parse(tt.ua).Arch
|
|
if got != tt.want {
|
|
t.Errorf("Parse(%q).Arch = %q, want %q", tt.ua, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLibc(t *testing.T) {
|
|
tests := []struct {
|
|
ua string
|
|
want buildmeta.Libc
|
|
}{
|
|
{"Linux 6.1.0 x86_64 musl", buildmeta.LibcMusl},
|
|
{"Linux 6.1.0 x86_64 gnu", buildmeta.LibcGNU},
|
|
{"Linux 6.1.0 x86_64 linux", buildmeta.LibcGNU},
|
|
{"MS AMD64 msvc", buildmeta.LibcMSVC},
|
|
{"Microsoft Windows", buildmeta.LibcMSVC},
|
|
{"Darwin 23.1.0 arm64", buildmeta.LibcNone},
|
|
{"-", ""},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.ua, func(t *testing.T) {
|
|
got := uadetect.Parse(tt.ua).Libc
|
|
if got != tt.want {
|
|
t.Errorf("Parse(%q).Libc = %q, want %q", tt.ua, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFullParse(t *testing.T) {
|
|
r := uadetect.Parse("Darwin 23.1.0 arm64")
|
|
if r.OS != buildmeta.OSDarwin {
|
|
t.Errorf("OS = %q, want %q", r.OS, buildmeta.OSDarwin)
|
|
}
|
|
if r.Arch != buildmeta.ArchARM64 {
|
|
t.Errorf("Arch = %q, want %q", r.Arch, buildmeta.ArchARM64)
|
|
}
|
|
if r.Libc != buildmeta.LibcNone {
|
|
t.Errorf("Libc = %q, want %q", r.Libc, buildmeta.LibcNone)
|
|
}
|
|
}
|