forked from nixys/nxs-go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usergroup_test.go
127 lines (96 loc) · 2.63 KB
/
usergroup_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
package zabbix
import (
"reflect"
"testing"
)
const (
testUsergroupName = "testUsergroupName"
testUserAdminID = 1
)
func TestUsergroupCRUD(t *testing.T) {
var z Context
// Login
loginTest(&z, t)
defer logoutTest(&z, t)
// Create and delete
ugCreatedIDs := testUsergroupCreate(t, z)
defer testUsergroupDelete(t, z, ugCreatedIDs)
// Update
testUsergroupUpdate(t, z, ugCreatedIDs)
// Get
testUsergroupGet(t, z, ugCreatedIDs)
}
func testUsergroupCreate(t *testing.T, z Context) []int {
ugCreatedIDs, _, err := z.UsergroupCreate([]UsergroupObject{
{
Name: testUsergroupName,
},
})
if err != nil {
t.Fatal("Usergroup create error:", err)
}
if len(ugCreatedIDs) == 0 {
t.Fatal("Usergroup create error: empty IDs array")
}
t.Logf("Usergroup create: success")
return ugCreatedIDs
}
func testUsergroupUpdate(t *testing.T, z Context, ugCreatedIDs []int) []int {
var ugObjects []UsergroupObject
// Preparing usergroup objects array to update
for _, i := range ugCreatedIDs {
ugObjects = append(ugObjects, UsergroupObject{
UsrgrpID: i,
UserIDs: []int{testUserAdminID},
})
}
ugUpdatedIDs, _, err := z.UsergroupUpdate(ugObjects)
if err != nil {
t.Fatal("Usergroup update error:", err)
}
if len(ugUpdatedIDs) == 0 {
t.Fatal("Usergroup update error: empty IDs array")
}
if reflect.DeepEqual(ugUpdatedIDs, ugCreatedIDs) == false {
t.Fatal("Usergroup update error: IDs arrays for created and updated usergroup are mismatch")
}
t.Logf("Usergroup update: success")
return ugUpdatedIDs
}
func testUsergroupDelete(t *testing.T, z Context, ugCreatedIDs []int) []int {
ugDeletedIDs, _, err := z.UsergroupDelete(ugCreatedIDs)
if err != nil {
t.Fatal("Usergroup delete error:", err)
}
if len(ugDeletedIDs) == 0 {
t.Fatal("Usergroup delete error: empty IDs array")
}
if reflect.DeepEqual(ugDeletedIDs, ugCreatedIDs) == false {
t.Fatal("Usergroup delete error: IDs arrays for created and deleted usergroup are mismatch")
}
t.Logf("Usergroup delete: success")
return ugDeletedIDs
}
func testUsergroupGet(t *testing.T, z Context, ugCreatedIDs []int) []UsergroupObject {
ugObjects, _, err := z.UsergroupGet(UsergroupGetParams{
UsrgrpIDs: ugCreatedIDs,
SelectRights: SelectExtendedOutput,
SelectUsers: SelectExtendedOutput,
GetParameters: GetParameters{
Filter: map[string]interface{}{
"name": testUsergroupName,
},
Output: SelectExtendedOutput,
},
})
if err != nil {
t.Error("Usergroup get error:", err)
} else {
if len(ugObjects) == 0 {
t.Error("Usergroup get error: unable to find created usergroup")
} else {
t.Logf("Usergroup get: success")
}
}
return ugObjects
}