-
Notifications
You must be signed in to change notification settings - Fork 15
/
template_test.go
106 lines (81 loc) · 2.1 KB
/
template_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
package zabbix
import (
"reflect"
"testing"
)
const (
testTemplateName = "testTemplate"
)
func TestTemplateCRUD(t *testing.T) {
var z Context
// Login
loginTest(&z, t)
defer logoutTest(&z, t)
// Preparing auxiliary data
hgCreatedIDs := testHostgroupCreate(t, z)
defer testHostgroupDelete(t, z, hgCreatedIDs)
// Create and delete
tCreatedIDs := testTemplateCreate(t, z, hgCreatedIDs)
defer testTemplateDelete(t, z, tCreatedIDs)
// Get
testTemplateGet(t, z, tCreatedIDs, hgCreatedIDs)
}
func testTemplateCreate(t *testing.T, z Context, hgCreatedIDs []int) []int {
var groups []HostgroupObject
// Add groups to template
for _, e := range hgCreatedIDs {
groups = append(groups, HostgroupObject{
GroupID: e,
})
}
tCreatedIDs, _, err := z.TemplateCreate([]TemplateObject{
{
Host: testTemplateName,
Groups: groups,
},
})
if err != nil {
t.Fatal("Template create error:", err)
}
if len(tCreatedIDs) == 0 {
t.Fatal("Template create error: empty IDs array")
}
t.Logf("Template create: success")
return tCreatedIDs
}
func testTemplateDelete(t *testing.T, z Context, tCreatedIDs []int) []int {
tDeletedIDs, _, err := z.TemplateDelete(tCreatedIDs)
if err != nil {
t.Fatal("Template delete error:", err)
}
if len(tDeletedIDs) == 0 {
t.Fatal("Template delete error: empty IDs array")
}
if reflect.DeepEqual(tDeletedIDs, tCreatedIDs) == false {
t.Fatal("Template delete error: IDs arrays for created and deleted template are mismatch")
}
t.Logf("Template delete: success")
return tDeletedIDs
}
func testTemplateGet(t *testing.T, z Context, tCreatedIDs, hgCreatedIDs []int) []TemplateObject {
tObjects, _, err := z.TemplateGet(TemplateGetParams{
TemplateIDs: tCreatedIDs,
GroupIDs: hgCreatedIDs,
GetParameters: GetParameters{
Filter: map[string]interface{}{
"name": testTemplateName,
},
Output: SelectExtendedOutput,
},
})
if err != nil {
t.Error("Template get error:", err)
} else {
if len(tObjects) == 0 {
t.Error("Template get error: unable to find created template")
} else {
t.Logf("Template get: success")
}
}
return tObjects
}