2021-10-11 00:02:51 -07:00
|
|
|
//go:build !darwin && !windows
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
2022-01-26 01:23:18 -08:00
|
|
|
"oh-my-posh/mock"
|
|
|
|
|
2021-10-11 00:02:51 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSpotifyWsl(t *testing.T) {
|
|
|
|
cases := []struct {
|
|
|
|
Case string
|
|
|
|
ExpectedString string
|
|
|
|
ExpectedEnabled bool
|
|
|
|
ExecOutput string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Case: "Spotify not running",
|
|
|
|
ExpectedString: " - ",
|
|
|
|
ExpectedEnabled: false,
|
|
|
|
ExecOutput: "INFO: No tasks are running which match the specified criteria.\n",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Case: "Spotify stopped/paused",
|
|
|
|
ExpectedString: " - ",
|
|
|
|
ExpectedEnabled: false,
|
|
|
|
ExecOutput: `"Spotify.exe","21824","Console","1","124,928 K","Running","PC\user","0:09:44","Spotify Premium"
|
|
|
|
"Spotify.exe","21876","Console","1","25,520 K","Running","PC\user","0:00:00","N/A"
|
|
|
|
"Spotify.exe","21988","Console","1","60,840 K","Not Responding","PC\user","0:04:56","AngleHiddenWindow"
|
|
|
|
"Spotify.exe","22052","Console","1","29,040 K","Unknown","PC\user","0:00:00","N/A"
|
|
|
|
"Spotify.exe","22072","Console","1","43,960 K","Unknown","PC\user","0:01:50","N/A"
|
|
|
|
"Spotify.exe","10404","Console","1","256,924 K","Unknown","PC\user","0:10:49","N/A"`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Case: "Spotify playing",
|
|
|
|
ExpectedString: "\ue602 Candlemass - Spellbreaker",
|
|
|
|
ExpectedEnabled: true,
|
|
|
|
ExecOutput: `"Spotify.exe","21824","Console","1","124,928 K","Running","PC\user","0:09:44","Candlemass - Spellbreaker"
|
|
|
|
"Spotify.exe","21876","Console","1","25,520 K","Running","PC\user","0:00:00","N/A"
|
|
|
|
"Spotify.exe","21988","Console","1","60,840 K","Not Responding","PC\user","0:04:56","AngleHiddenWindow"
|
|
|
|
"Spotify.exe","22052","Console","1","29,040 K","Unknown","PC\user","0:00:00","N/A"
|
|
|
|
"Spotify.exe","22072","Console","1","43,960 K","Unknown","PC\user","0:01:50","N/A"
|
|
|
|
"Spotify.exe","10404","Console","1","256,924 K","Unknown","PC\user","0:10:49","N/A"`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Case: "tasklist.exe not in path",
|
|
|
|
ExpectedString: " - ",
|
|
|
|
ExpectedEnabled: false,
|
|
|
|
ExecOutput: ""},
|
|
|
|
}
|
|
|
|
for _, tc := range cases {
|
2022-01-26 01:23:18 -08:00
|
|
|
env := new(mock.MockedEnvironment)
|
2022-01-23 12:37:51 -08:00
|
|
|
env.On("IsWsl").Return(true)
|
|
|
|
env.On("RunCommand", "tasklist.exe", []string{"/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH"}).Return(tc.ExecOutput, nil)
|
2021-10-11 00:02:51 -07:00
|
|
|
s := &spotify{
|
2022-01-01 11:08:08 -08:00
|
|
|
env: env,
|
|
|
|
props: properties{},
|
2021-10-11 00:02:51 -07:00
|
|
|
}
|
|
|
|
assert.Equal(t, tc.ExpectedEnabled, s.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
2022-01-26 01:23:18 -08:00
|
|
|
assert.Equal(t, tc.ExpectedString, renderTemplate(env, s.template(), s), fmt.Sprintf("Failed in case: %s", tc.Case))
|
2021-10-11 00:02:51 -07:00
|
|
|
}
|
|
|
|
}
|