forked from nytm/go-grafana-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
team_test.go
90 lines (73 loc) · 1.76 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
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
package gapi
import (
"testing"
"github.com/gobs/pretty"
)
const (
creatTeamJSON = `{"message":"Team created","teamId":2}`
getTeamJSON = `{
"id": 1,
"orgId": 1,
"name": "MyTestTeam",
"email": "",
"created": "2017-12-15T10:40:45+01:00",
"updated": "2017-12-15T10:40:45+01:00"
}`
updateTeamJSON = `{"message":"Team updated"}`
deleteTeamJSON = `{"message":"Team deleted"}`
addTeamMemberJSON = `{"message":"Member added to Team"}`
)
func TestNewTeam(t *testing.T) {
server, client := gapiTestTools(200, creatTeamJSON)
defer server.Close()
team, err := client.NewTeam("test")
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(team))
if team.Id != 2 {
t.Error("Create Team Error.")
}
}
func TestGetTeam(t *testing.T) {
server, client := gapiTestTools(200, getTeamJSON)
defer server.Close()
resp, err := client.Team(1)
if err != nil {
t.Error(err)
}
t.Log(pretty.PrettyFormat(resp))
team := Team{
Id: 1,
OrgId: 1,
Email: "",
Name: "MyTestTeam",
}
if resp != team {
t.Error("Not correctly parsing returned team.")
}
}
func TestUpdateTeam(t *testing.T) {
server, client := gapiTestTools(200, updateTeamJSON)
defer server.Close()
err := client.UpdateTeam("1", "test team 2")
if err != nil {
t.Error(err)
}
}
func TestDeleteTeam(t *testing.T) {
server, client := gapiTestTools(200, deleteTeamJSON)
defer server.Close()
err := client.DeleteTeam("1")
if err != nil {
t.Error(err)
}
}
func TestAddTeamMember(t *testing.T) {
server, client := gapiTestTools(200, addTeamMemberJSON)
defer server.Close()
err := client.AddTeamMember("1", 1)
if err != nil {
t.Error(err)
}
}