This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
team_external_group_test.go
85 lines (73 loc) · 1.67 KB
/
team_external_group_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
package gapi
import (
"testing"
"github.com/esnet/grafana-swagger-api-golang/goclient/client/sync_team_groups"
"github.com/esnet/grafana-swagger-api-golang/goclient/models"
"github.com/gobs/pretty"
)
const (
getTeamGroupsJSON = `
[
{
"orgId": 1,
"teamId": 1,
"groupId": "test"
}
]
`
createdTeamGroupJSON = `
{
"message":"Group added to Team"
}
`
deletedTeamGroupJSON = `
{
"message":"Team Group removed"
}
`
)
func TestTeamGroups(t *testing.T) {
mocksrv, client := gapiTestTools(t, 200, getTeamGroupsJSON)
defer mocksrv.Close()
teamGroups, err := client.SyncTeamGroups.GetTeamGroupsAPI(
sync_team_groups.NewGetTeamGroupsAPIParams().
WithTeamID(1),
nil,
)
if err != nil {
t.Fatal(err)
}
t.Log(pretty.PrettyFormat(teamGroups))
if len(teamGroups.Payload) != 1 {
t.Error("Length of returned teamGroups should be 1")
}
if teamGroups.Payload[0].TeamID != 1 || teamGroups.Payload[0].OrgID != 1 || teamGroups.Payload[0].GroupID != "test" {
t.Error("Not correctly parsing returned teamGroups.")
}
}
func TestNewTeamGroup(t *testing.T) {
mocksrv, client := gapiTestTools(t, 200, createdTeamGroupJSON)
defer mocksrv.Close()
_, err := client.SyncTeamGroups.AddTeamGroupAPI(
sync_team_groups.NewAddTeamGroupAPIParams().WithTeamID(1).WithBody(&models.TeamGroupMapping{
GroupID: "test",
}),
nil,
)
if err != nil {
t.Fatal(err)
}
}
func TestDeleteTeamGroup(t *testing.T) {
server, client := gapiTestTools(t, 200, deletedTeamGroupJSON)
defer server.Close()
_, err := client.SyncTeamGroups.RemoveTeamGroupAPI(
sync_team_groups.NewRemoveTeamGroupAPIParams().
WithTeamID(1).
WithGroupID("test"),
nil,
)
if err != nil {
t.Fatal(err)
}
}