forked from claranet/go-zabbix-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host_group_test.go
66 lines (55 loc) · 1.5 KB
/
host_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
package zabbix_test
import (
"fmt"
"math/rand"
"reflect"
"testing"
zapi "github.com/claranet/go-zabbix-api"
)
func testCreateHostGroup(t *testing.T) *zapi.HostGroup {
hostGroups := zapi.HostGroups{{Name: fmt.Sprintf("zabbix-testing-%d", rand.Int())}}
err := testGetAPI(t).HostGroupsCreate(hostGroups)
if err != nil {
t.Fatal(err)
}
return &hostGroups[0]
}
func testDeleteHostGroup(hostGroup *zapi.HostGroup, t *testing.T) {
err := testGetAPI(t).HostGroupsDelete(zapi.HostGroups{*hostGroup})
if err != nil {
t.Fatal(err)
}
}
func TestHostGroups(t *testing.T) {
api := testGetAPI(t)
groups, err := api.HostGroupsGet(zapi.Params{})
if err != nil {
t.Fatal(err)
}
hostGroup := testCreateHostGroup(t)
if hostGroup.GroupID == "" || hostGroup.Name == "" {
t.Errorf("Something is empty: %#v", hostGroup)
}
hostGroup2, err := api.HostGroupGetByID(hostGroup.GroupID)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(hostGroup, hostGroup2) {
t.Errorf("Error getting group.\nOld group: %#v\nNew group: %#v", hostGroup, hostGroup2)
}
groups2, err := api.HostGroupsGet(zapi.Params{})
if err != nil {
t.Fatal(err)
}
if len(groups2) != len(groups)+1 {
t.Errorf("Error creating group.\nOld groups: %#v\nNew groups: %#v", groups, groups2)
}
testDeleteHostGroup(hostGroup, t)
groups2, err = api.HostGroupsGet(zapi.Params{})
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(groups, groups2) {
t.Errorf("Error deleting group.\nOld groups: %#v\nNew groups: %#v", groups, groups2)
}
}