feat(platform): detect distro, WSL, and architecture

This commit is contained in:
MDietermann
2026-04-13 19:59:04 +02:00
parent ea0d793461
commit 3b666615d7
2 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
package platform
import (
"strings"
"testing"
)
func TestParseDistroArch(t *testing.T) {
osRelease := `NAME="Arch Linux"
ID=arch
ID_LIKE=archlinux
`
if got := parseDistro(strings.NewReader(osRelease)); got != DistroArch {
t.Fatalf("got %v", got)
}
}
func TestParseDistroUbuntu(t *testing.T) {
osRelease := `NAME="Ubuntu"
ID=ubuntu
`
if got := parseDistro(strings.NewReader(osRelease)); got != DistroUnknown {
t.Fatalf("got %v", got)
}
}
func TestParseDistroQuoted(t *testing.T) {
osRelease := `ID="arch"
`
if got := parseDistro(strings.NewReader(osRelease)); got != DistroArch {
t.Fatalf("got %v", got)
}
}
func TestDetectReturnsArch(t *testing.T) {
p, err := Detect()
if err != nil {
t.Fatal(err)
}
if p.Arch == "" {
t.Fatal("arch is empty")
}
// We don't assert Distro here because the test host may not be Arch.
// The parse-level tests above cover that logic.
}