mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
64 lines
1.3 KiB
Go
64 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestWiFiSegment(t *testing.T) {
|
|
cases := []struct {
|
|
Case string
|
|
ExpectedString string
|
|
ExpectedEnabled bool
|
|
Network *wifiInfo
|
|
WifiError error
|
|
DisplayError bool
|
|
}{
|
|
{
|
|
Case: "No error and nil network",
|
|
},
|
|
{
|
|
Case: "Error and nil network",
|
|
WifiError: errors.New("oh noes"),
|
|
},
|
|
{
|
|
Case: "Display error and nil network",
|
|
WifiError: errors.New("oh noes"),
|
|
ExpectedString: "oh noes",
|
|
DisplayError: true,
|
|
ExpectedEnabled: true,
|
|
},
|
|
{
|
|
Case: "Display wifi state",
|
|
ExpectedString: "pretty fly for a wifi",
|
|
ExpectedEnabled: true,
|
|
Network: &wifiInfo{
|
|
SSID: "pretty fly for a wifi",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
env := new(MockedEnvironment)
|
|
env.On("getPlatform").Return(windowsPlatform)
|
|
env.On("isWsl").Return(false)
|
|
env.On("getWifiNetwork").Return(tc.Network, tc.WifiError)
|
|
env.onTemplate()
|
|
|
|
w := &wifi{
|
|
env: env,
|
|
props: properties{
|
|
DisplayError: tc.DisplayError,
|
|
SegmentTemplate: "{{ if .Error }}{{ .Error }}{{ else }}{{ .SSID }}{{ end }}",
|
|
},
|
|
}
|
|
|
|
assert.Equal(t, tc.ExpectedEnabled, w.enabled(), tc.Case)
|
|
if tc.Network != nil || tc.DisplayError {
|
|
assert.Equal(t, tc.ExpectedString, w.string(), tc.Case)
|
|
}
|
|
}
|
|
}
|