forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 1
/
segment_ytm_test.go
91 lines (81 loc) · 2.29 KB
/
segment_ytm_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestYTMStringPlayingSong(t *testing.T) {
expected := "\ue602 Candlemass - Spellbreaker"
y := &ytm{
artist: "Candlemass",
track: "Spellbreaker",
status: playing,
}
assert.Equal(t, expected, y.string())
}
func TestYTMStringPausedSong(t *testing.T) {
expected := "\uF8E3 Candlemass - Spellbreaker"
y := &ytm{
artist: "Candlemass",
track: "Spellbreaker",
status: paused,
}
assert.Equal(t, expected, y.string())
}
func TestYTMStringStoppedSong(t *testing.T) {
expected := "\uf04d "
y := &ytm{
artist: "Candlemass",
track: "Spellbreaker",
status: stopped,
}
assert.Equal(t, expected, y.string())
}
func bootstrapYTMDATest(json string, err error) *ytm {
url := "http://localhost:1337"
env := new(MockedEnvironment)
env.On("doGet", url+"/query").Return([]byte(json), err)
props := &properties{
values: map[Property]interface{}{
APIURL: url,
},
}
ytm := &ytm{
env: env,
props: props,
}
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)
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)
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)
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)
}