2020-10-07 12:01:03 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-02-25 21:51:03 -08:00
|
|
|
func TestOSInfo(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Case string
|
|
|
|
ExpectedString string
|
|
|
|
GOOS string
|
|
|
|
WSLDistro string
|
|
|
|
Platform string
|
|
|
|
DisplayDistroName bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Case: "WSL debian - icon",
|
|
|
|
ExpectedString: "WSL at \uf306",
|
|
|
|
GOOS: "linux",
|
|
|
|
WSLDistro: "debian",
|
|
|
|
Platform: "debian",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Case: "WSL debian - name",
|
|
|
|
ExpectedString: "WSL at burps",
|
|
|
|
GOOS: "linux",
|
|
|
|
WSLDistro: "burps",
|
|
|
|
Platform: "debian",
|
|
|
|
DisplayDistroName: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Case: "plain linux - icon",
|
|
|
|
ExpectedString: "\uf306",
|
|
|
|
GOOS: "linux",
|
|
|
|
Platform: "debian",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Case: "plain linux - name",
|
|
|
|
ExpectedString: "debian",
|
|
|
|
GOOS: "linux",
|
|
|
|
Platform: "debian",
|
|
|
|
DisplayDistroName: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Case: "windows",
|
|
|
|
ExpectedString: "windows",
|
|
|
|
GOOS: "windows",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Case: "darwin",
|
|
|
|
ExpectedString: "darwin",
|
|
|
|
GOOS: "darwin",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Case: "unknown",
|
|
|
|
ExpectedString: "unknown",
|
|
|
|
GOOS: "unknown",
|
2020-10-21 19:49:14 -07:00
|
|
|
},
|
|
|
|
}
|
2021-02-25 21:51:03 -08:00
|
|
|
for _, tc := range cases {
|
|
|
|
env := new(MockedEnvironment)
|
2022-01-15 11:37:46 -08:00
|
|
|
env.On("getRuntimeGOOS").Return(tc.GOOS)
|
2021-02-25 21:51:03 -08:00
|
|
|
env.On("getenv", "WSL_DISTRO_NAME").Return(tc.WSLDistro)
|
2022-01-15 11:37:46 -08:00
|
|
|
env.On("getPlatform").Return(tc.Platform)
|
2021-11-26 01:37:33 -08:00
|
|
|
osInfo := &osInfo{
|
|
|
|
env: env,
|
2022-01-01 11:08:08 -08:00
|
|
|
props: properties{
|
2021-02-25 21:51:03 -08:00
|
|
|
WSL: "WSL",
|
|
|
|
WSLSeparator: " at ",
|
|
|
|
DisplayDistroName: tc.DisplayDistroName,
|
|
|
|
Windows: "windows",
|
|
|
|
MacOS: "darwin",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
assert.Equal(t, tc.ExpectedString, osInfo.string(), tc.Case)
|
2021-04-24 12:31:56 -07:00
|
|
|
if tc.WSLDistro != "" {
|
|
|
|
assert.Equal(t, tc.WSLDistro, osInfo.OS, tc.Case)
|
|
|
|
} else if tc.Platform != "" {
|
|
|
|
assert.Equal(t, tc.Platform, osInfo.OS, tc.Case)
|
|
|
|
} else {
|
|
|
|
assert.Equal(t, tc.GOOS, osInfo.OS, tc.Case)
|
|
|
|
}
|
2020-10-21 19:49:14 -07:00
|
|
|
}
|
|
|
|
}
|