forked from AlekSi/zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host_group_test.go
65 lines (55 loc) · 1.4 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
package zabbix_test
import (
. "."
"fmt"
"math/rand"
"reflect"
"testing"
)
func CreateHostGroup(t *testing.T) *HostGroup {
hostGroups := HostGroups{{Name: fmt.Sprintf("zabbix-testing-%d", rand.Int())}}
err := getAPI(t).HostGroupsCreate(hostGroups)
if err != nil {
t.Fatal(err)
}
return &hostGroups[0]
}
func DeleteHostGroup(hostGroup *HostGroup, t *testing.T) {
err := getAPI(t).HostGroupsDelete(HostGroups{*hostGroup})
if err != nil {
t.Fatal(err)
}
}
func TestHostGroups(t *testing.T) {
api := getAPI(t)
groups, err := api.HostGroupsGet(Params{})
if err != nil {
t.Fatal(err)
}
hostGroup := CreateHostGroup(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(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)
}
DeleteHostGroup(hostGroup, t)
groups2, err = api.HostGroupsGet(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)
}
}