46 lines
899 B
Go
46 lines
899 B
Go
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.
|
|
}
|