oh-my-posh/src/segment_ytm_test.go

59 lines
1.6 KiB
Go
Raw Normal View History

package main
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func bootstrapYTMDATest(json string, err error) *ytm {
url := "http://127.0.0.1:9863"
env := new(MockedEnvironment)
2022-01-07 10:41:58 -08:00
env.On("HTTPRequest", url+"/query").Return([]byte(json), err)
2021-11-26 01:37:33 -08:00
ytm := &ytm{
env: env,
2022-01-01 11:08:08 -08:00
props: properties{
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)
}