-
Notifications
You must be signed in to change notification settings - Fork 15
/
hostgroup_test.go
91 lines (69 loc) · 1.76 KB
/
hostgroup_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
package zabbix
import (
"reflect"
"testing"
)
const (
testHostgroupName = "testHostgroup"
)
func TestHostgroupCRUD(t *testing.T) {
var z Context
// Login
loginTest(&z, t)
defer logoutTest(&z, t)
// Create and delete
hgCreatedIDs := testHostgroupCreate(t, z)
defer testHostgroupDelete(t, z, hgCreatedIDs)
// Get
testHostgroupGet(t, z, hgCreatedIDs)
}
func testHostgroupCreate(t *testing.T, z Context) []int {
hgCreatedIDs, _, err := z.HostgroupCreate([]HostgroupObject{
{
Name: testHostgroupName,
},
})
if err != nil {
t.Fatal("Hostgroup create error:", err)
}
if len(hgCreatedIDs) == 0 {
t.Fatal("Hostgroup create error: empty IDs array")
}
t.Logf("Hostgroup create: success")
return hgCreatedIDs
}
func testHostgroupDelete(t *testing.T, z Context, hgCreatedIDs []int) []int {
hgDeletedIDs, _, err := z.HostgroupDelete(hgCreatedIDs)
if err != nil {
t.Fatal("Hostgroup delete error:", err)
}
if len(hgDeletedIDs) == 0 {
t.Fatal("Hostgroup delete error: empty IDs array")
}
if reflect.DeepEqual(hgDeletedIDs, hgCreatedIDs) == false {
t.Fatal("Hostgroup delete error: IDs arrays for created and deleted hostgroup are mismatch")
}
t.Logf("Hostgroup delete: success")
return hgDeletedIDs
}
func testHostgroupGet(t *testing.T, z Context, hgCreatedIDs []int) []HostgroupObject {
hgObjects, _, err := z.HostgroupGet(HostgroupGetParams{
GroupIDs: hgCreatedIDs,
GetParameters: GetParameters{
Filter: map[string]interface{}{
"name": testHostgroupName,
},
Output: SelectExtendedOutput,
},
})
if err != nil {
t.Error("Hostgroup get error:", err)
} else {
if len(hgObjects) == 0 {
t.Error("Hostgroup get error: unable to find created hostgroup")
} else {
t.Logf("Hostgroup get: success")
}
}
return hgObjects
}