-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_test.go
182 lines (143 loc) · 3.15 KB
/
core_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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package GoGrooveShark
import (
"fmt"
"testing"
)
// Various things used during testing
var (
GS_SAMPLE_SONG_ID = 30717514
GS_SAMPLE_ALBUM_ID = 3857559
GS_SAMPLE_PLAYLIST_NAME = "_TEST_PLAYLIST_"
)
func ExampleCreateSignature() {
fmt.Println(createSignature("{'x': 'some json value'}", "1234567890abcdefghijklmnopqrstuv"))
// Output: 9bdf0ebbb4cb2c945022670a16c6b5dc
}
func TestInitGrooveShark(t *testing.T) {
gs := NewGrooveShark("pub", "secrets")
if gs.publicKey != "pub" {
t.Fail()
}
if gs.secretKey != "secrets" {
t.Fail()
}
}
func CreateGrooveShark() *GrooveShark {
return NewGrooveShark(API_KEY, API_SECRET)
}
func TestGoodApiCall(t *testing.T) {
out, err := CreateGrooveShark().apiCall("pingService", make(map[string]interface{}))
if err != nil {
t.Fatalf("Error param is set")
}
if out == nil {
t.Fatalf("out param is not set")
}
if out.getError() != nil {
t.Fatalf("Response is not ok")
}
}
func TestBadApiCall(t *testing.T) {
out, err := CreateGrooveShark().apiCall("pingServiceNOTAMETHOD", make(map[string]interface{}))
if err != nil {
t.Fatalf("Error param is set")
}
if out == nil {
t.Fatalf("out param is not set")
}
if out.getError() == nil {
t.Fatalf("Response is ok")
}
}
func TestGetPlaylist(t *testing.T) {
playlist, err := CreateGrooveShark().GetPlaylist("52262304", nil)
if err != nil {
t.Fatal(err)
}
if playlist.UserID == 0 {
t.Fatal("Empty response")
}
}
func TestStartSession(t *testing.T) {
gs := CreateGrooveShark()
sessionId, err := gs.StartSession()
if err != nil {
t.Fatal(err)
}
if sessionId == nil {
t.Fatal("No session id returned")
}
if gs.sessionId != *sessionId {
t.Fatal("GS session does not match.")
}
t.Logf("SessionID: %s", gs.sessionId)
}
func TestAuthenticate(t *testing.T) {
gs := CreateGrooveShark()
user, err := gs.Authenticate(GS_LOGIN, GS_PASSWORD)
if err != nil {
t.Fatal(err)
}
if user == nil {
t.Fatal("No user returned")
}
t.Logf("%+v", user)
}
func TestAddUserFavoriteSong(t *testing.T) {
gs := CreateGrooveShark()
_, err := gs.Authenticate(GS_LOGIN, GS_PASSWORD)
if err != nil {
t.Fatal(err)
}
err = gs.AddUserFavoriteSong(GS_SAMPLE_SONG_ID)
if err != nil {
t.Fatal(err)
}
}
func TestPingService(t *testing.T) {
gs := CreateGrooveShark()
msg, err := gs.PingService()
if err != nil {
t.Fatal(err)
}
if msg == nil {
t.Fatal("No hello world message returned")
}
t.Logf(*msg)
}
func TestCreatePlaylist(t *testing.T) {
gs := CreateGrooveShark()
_, err := gs.Authenticate(GS_LOGIN, GS_PASSWORD)
if err != nil {
t.Fatal(err)
}
msg, err := gs.CreatePlaylist(GS_SAMPLE_PLAYLIST_NAME, []int{GS_SAMPLE_SONG_ID})
if err != nil {
t.Fatal(err)
}
if msg == nil {
t.Fatal("No response returned")
}
if !msg.Success {
t.Fatal("Error returned")
}
t.Logf("%+v", msg)
}
func TestDeletePlaylist(t *testing.T) {
gs := CreateGrooveShark()
_, err := gs.Authenticate(GS_LOGIN, GS_PASSWORD)
if err != nil {
t.Fatal(err)
}
msg, err := gs.DeletePlaylist(80882182)
if err != nil {
t.Fatal(err)
}
if msg == nil {
t.Fatal("No response returned")
}
if !msg.Success {
t.Fatal("Error returned")
}
t.Logf("%+v", msg)
}