forked from slack-go/slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
team_test.go
55 lines (48 loc) · 1.32 KB
/
team_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
package slack
import (
"errors"
"net/http"
"testing"
)
var (
ErrIncorrectResponse = errors.New("Response is incorrect")
)
func getTeamInfo(rw http.ResponseWriter, r *http.Request) {
rw.Header().Set("Content-Type", "application/json")
response := []byte(`{"ok": true, "team": {
"id": "F0UWHUX",
"name": "notalar",
"domain": "notalar",
"icon": {
"image_34": "https://slack.global.ssl.fastly.net/66f9/img/avatars-teams/ava_0002-34.png",
"image_44": "https://slack.global.ssl.fastly.net/66f9/img/avatars-teams/ava_0002-44.png",
"image_55": "https://slack.global.ssl.fastly.net/66f9/img/avatars-teams/ava_0002-55.png",
"image_default": true
}
}}`)
rw.Write(response)
}
func TestGetTeamInfo(t *testing.T) {
http.HandleFunc("/team.info", getTeamInfo)
once.Do(startServer)
SLACK_API = "http://" + serverAddr + "/"
api := New("testing-token")
teamInfo, err := api.GetTeamInfo()
if err != nil {
t.Errorf("Unexpected error: %s", err)
return
}
// t.Fatal refers to -> t.Errorf & return
if teamInfo.ID != "F0UWHUX" {
t.Fatal(ErrIncorrectResponse)
}
if teamInfo.Domain != "notalar" {
t.Fatal(ErrIncorrectResponse)
}
if teamInfo.Name != "notalar" {
t.Fatal(ErrIncorrectResponse)
}
if teamInfo.Icon == nil {
t.Fatal(ErrIncorrectResponse)
}
}