-
Notifications
You must be signed in to change notification settings - Fork 193
/
rest-team_integration_test.go
159 lines (132 loc) · 2.79 KB
/
rest-team_integration_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
package sdk_test
import (
"context"
"fmt"
"github.com/grafana-tools/sdk"
"testing"
)
func Test_Team_CRUD(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
teamName := "mytestteam"
teams, err := client.SearchTeams(ctx,
sdk.WithQuery(teamName),
sdk.WithPagesize(20),
sdk.WithPage(1),
)
if err != nil {
t.Fatal(err)
}
if len(teams.Teams) != 0 {
t.Fatalf("expected to get zero teams, got %#v", teams)
}
team := sdk.Team{
Name: teamName,
Email: fmt.Sprintf("%[email protected]", teamName),
OrgID: 1,
}
_, err = client.CreateTeam(ctx, team)
if err != nil {
t.Fatal(err)
}
teamByName, err := client.GetTeamByName(ctx, teamName)
if err != nil {
t.Fatal(err)
}
teamId := teamByName.ID
_, err = client.GetTeam(ctx, teamId)
if err != nil {
t.Fatal(err)
}
_, err = client.UpdateTeam(ctx, teamId, sdk.Team{
Name: "newTestTeam",
Email: "",
OrgID: 1,
})
if err != nil {
t.Fatal(err)
}
_, err = client.DeleteTeam(ctx, teamId)
if err != nil {
t.Fatal(err)
}
}
func Test_TeamMember_CRUD(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
teamName := "teamWithMembers"
team := sdk.Team{
Name: teamName,
Email: fmt.Sprintf("%[email protected]", teamName),
OrgID: 1,
}
_, err := client.CreateTeam(ctx, team)
if err != nil {
t.Fatal(err)
}
teamByName, err := client.GetTeamByName(ctx, teamName)
if err != nil {
t.Fatal(err)
}
teamId := teamByName.ID
teamMembers, err := client.GetTeamMembers(ctx, teamId)
if err != nil {
t.Fatal(err)
}
if len(teamMembers) != 0 {
t.Fatalf("expected to get zero teams members, got %#v", teamMembers)
}
actualUser, err := client.GetActualUser(ctx)
if err != nil {
t.Fatal(err)
}
_, err = client.AddTeamMember(ctx, teamId, actualUser.ID)
if err != nil {
t.Fatal(err)
}
teamMembers, err = client.GetTeamMembers(ctx, teamId)
if err != nil {
t.Fatal(err)
}
if len(teamMembers) != 1 {
t.Fatalf("expected to get one teams members, got %#v", teamMembers)
}
_, err = client.DeleteTeamMember(ctx, teamId, actualUser.ID)
if err != nil {
t.Fatal(err)
}
}
func Test_TeamPreferences(t *testing.T) {
shouldSkip(t)
client := getClient(t)
ctx := context.Background()
teamName := "teamWithPreferences"
team := sdk.Team{
Name: teamName,
Email: fmt.Sprintf("%[email protected]", teamName),
OrgID: 1,
}
_, err := client.CreateTeam(ctx, team)
if err != nil {
t.Fatal(err)
}
teamByName, err := client.GetTeamByName(ctx, teamName)
if err != nil {
t.Fatal(err)
}
teamId := teamByName.ID
_, err = client.GetTeamPreferences(ctx, teamId)
if err != nil {
t.Fatal(err)
}
_, err = client.UpdateTeamPreferences(ctx, teamId, sdk.TeamPreferences{
Theme: "dark",
HomeDashboardId: 0,
Timezone: "UTC",
})
if err != nil {
t.Fatal(err)
}
}