forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstars_test.go
87 lines (82 loc) · 1.69 KB
/
stars_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
package slack
import (
"net/http"
"reflect"
"testing"
)
var starsTests = struct {
in []byte
outItems []StarredItem
outPaging *Paging
}{
[]byte(`{"ok": true,
"items": [
{
"type": "message",
"channel": "C2147483705"
},
{
"type": "file"
},
{
"type": "file_comment"
},
{
"type": "channel",
"channel": "C2147483705"
}
],
"paging": {
"count": 100,
"total": 4,
"page": 1,
"pages": 1
}}`),
[]StarredItem{
{
Type: "message",
ChannelId: "C2147483705",
},
{
Type: "file",
},
{
Type: "file_comment",
},
{
Type: "channel",
ChannelId: "C2147483705",
},
},
&Paging{
Count: 100,
Total: 4,
Page: 1,
Pages: 1,
},
}
func getStarredHandler(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "application/json")
// XXX: I stripped the actual content just to test this test Oo
// At some point I should add valid content here
rw.Write(starsTests.in)
}
func TestGetStarred(t *testing.T) {
http.HandleFunc("/stars.list", getStarredHandler)
once.Do(startServer)
SLACK_API = "http://" + serverAddr + "/"
api := New("testing-token")
response_items, response_paging, err := api.GetStarred(NewStarsParameters())
if err != nil {
t.Errorf("Unexpected error: %s", err)
return
}
eq := reflect.DeepEqual(response_items, starsTests.outItems)
if !eq {
t.Errorf("got %v; want %v", response_items, starsTests.outItems)
}
eq = reflect.DeepEqual(response_paging, starsTests.outPaging)
if !eq {
t.Errorf("got %v; want %v", response_paging, starsTests.outPaging)
}
}