forked from claranet/go-zabbix-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
template_group_test.go
68 lines (56 loc) · 1.7 KB
/
template_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
package zabbix_test
import (
"fmt"
"math/rand"
"reflect"
"testing"
zapi "github.com/claranet/go-zabbix-api"
)
func testCreateTemplateGroup(t *testing.T) *zapi.TemplateGroup {
TemplateGroups := zapi.TemplateGroups{{Name: fmt.Sprintf("zabbix-testing-%d", rand.Int())}}
err := testGetAPI(t).TemplateGroupsCreate(TemplateGroups)
if err != nil {
t.Fatal(err)
}
return &TemplateGroups[0]
}
func testDeleteTemplateGroup(TemplateGroup *zapi.TemplateGroup, t *testing.T) {
err := testGetAPI(t).TemplateGroupsDelete(zapi.TemplateGroups{*TemplateGroup})
if err != nil {
t.Fatal(err)
}
}
func TestTemplateGroups(t *testing.T) {
skipTestIfVersionLessThan(t, "6.2", "introduced support for Template Groups API")
api := testGetAPI(t)
groups, err := api.TemplateGroupsGet(zapi.Params{})
if err != nil {
t.Fatal(err)
}
TemplateGroup := testCreateTemplateGroup(t)
if TemplateGroup.GroupID == "" || TemplateGroup.Name == "" {
t.Errorf("Something is empty: %#v", TemplateGroup)
}
TemplateGroup2, err := api.TemplateGroupGetByID(TemplateGroup.GroupID)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(TemplateGroup, TemplateGroup2) {
t.Errorf("Error getting group.\nOld group: %#v\nNew group: %#v", TemplateGroup, TemplateGroup2)
}
groups2, err := api.TemplateGroupsGet(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)
}
testDeleteTemplateGroup(TemplateGroup, t)
groups2, err = api.TemplateGroupsGet(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)
}
}