oh-my-posh/src/segments/ytm_test.go

61 lines
1.7 KiB
Go
Raw Normal View History

2022-01-26 06:54:36 -08:00
package segments
import (
"errors"
"oh-my-posh/mock"
"oh-my-posh/properties"
"testing"
"github.com/stretchr/testify/assert"
)
2022-01-26 05:10:18 -08:00
func bootstrapYTMDATest(json string, err error) *Ytm {
url := "http://127.0.0.1:9863"
env := new(mock.MockedEnvironment)
2022-01-07 10:41:58 -08:00
env.On("HTTPRequest", url+"/query").Return([]byte(json), err)
2022-01-26 05:10:18 -08:00
ytm := &Ytm{
2021-11-26 01:37:33 -08:00
env: env,
props: properties.Map{
APIURL: url,
},
}
return ytm
}
func TestYTMDAPlaying(t *testing.T) {
json := `{ "player": { "hasSong": true, "isPaused": false }, "track": { "author": "Candlemass", "title": "Spellbreaker" } }`
ytm := bootstrapYTMDATest(json, nil)
err := ytm.setStatus()
assert.NoError(t, err)
2022-01-22 10:46:56 -08:00
assert.Equal(t, "playing", ytm.Status)
assert.Equal(t, "Candlemass", ytm.Artist)
assert.Equal(t, "Spellbreaker", ytm.Track)
}
func TestYTMDAPaused(t *testing.T) {
json := `{ "player": { "hasSong": true, "isPaused": true }, "track": { "author": "Candlemass", "title": "Spellbreaker" } }`
ytm := bootstrapYTMDATest(json, nil)
err := ytm.setStatus()
assert.NoError(t, err)
2022-01-22 10:46:56 -08:00
assert.Equal(t, "paused", ytm.Status)
assert.Equal(t, "Candlemass", ytm.Artist)
assert.Equal(t, "Spellbreaker", ytm.Track)
}
func TestYTMDAStopped(t *testing.T) {
json := `{ "player": { "hasSong": false }, "track": { "author": "", "title": "" } }`
ytm := bootstrapYTMDATest(json, nil)
err := ytm.setStatus()
assert.NoError(t, err)
2022-01-22 10:46:56 -08:00
assert.Equal(t, "stopped", ytm.Status)
assert.Equal(t, "", ytm.Artist)
assert.Equal(t, "", ytm.Track)
}
func TestYTMDAError(t *testing.T) {
json := `{ "player": { "hasSong": false }, "track": { "author": "", "title": "" } }`
ytm := bootstrapYTMDATest(json, errors.New("Oh noes"))
enabled := ytm.Enabled()
assert.False(t, enabled)
}