oh-my-posh/src/segment_wifi_test.go

64 lines
1.3 KiB
Go
Raw Normal View History

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()
2021-11-26 01:37:33 -08:00
w := &wifi{
env: env,
2022-01-01 11:08:08 -08:00
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)
}
}
}