forked from claranet/go-zabbix-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
item_prototype_test.go
71 lines (58 loc) · 1.8 KB
/
item_prototype_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
package zabbix_test
import (
"testing"
dd "github.com/atypon/go-zabbix-api"
)
func testCreateItemPrototype(template *dd.Template, lldRule *dd.LLDRule, t *testing.T) *dd.ItemPrototype {
items := dd.ItemPrototypes{{
RuleID: lldRule.ItemID,
Delay: "30",
HostID: template.TemplateID,
InterfaceID: "0",
Key: "key.lala.lolo",
Type: dd.ZabbixAgent,
Name: "item prototype test",
ValueType: dd.Unsigned,
}}
err := testGetAPI(t).ItemPrototypesCreate(items)
if err != nil {
t.Fatal(err)
}
return &items[0]
}
func testDeleteItemPrototype(item *dd.ItemPrototype, t *testing.T) {
err := testGetAPI(t).ItemPrototypesDelete(dd.ItemPrototypes{*item})
if err != nil {
t.Fatal(err)
}
}
func testItemPrototype(t *testing.T) {
api := testGetAPI(t)
templateGroup := testCreateTemplateGroup(t)
defer testDeleteTemplateGroup(templateGroup, t)
template := testCreateTemplate(templateGroup, t)
defer testDeleteTemplate(template, t)
lldRule := testCreateLLDRule(template, t)
defer testDeleteLLDRule(lldRule, t)
itemPrototype := testCreateItemPrototype(template, lldRule, t)
getItemPrototype, err := api.ItemPrototypesGet(dd.Params{"itemids": itemPrototype.ItemID})
if err != nil {
t.Error(err)
}
if len(getItemPrototype) != 1 {
t.Errorf("Expecting one result and got : %d", len(getItemPrototype))
}
itemPrototype.Name = "update_item_prototype_name"
err = api.ItemPrototypesUpdate(dd.ItemPrototypes{*itemPrototype})
if err != nil {
t.Error(err)
}
getByIdItemPrototype, err := api.ItemPrototypeGetByID(itemPrototype.ItemID)
if err != nil {
t.Error(err)
}
if getByIdItemPrototype.Name != itemPrototype.Name {
t.Errorf("Item prototype name is %q and should be %q", getByIdItemPrototype.Name, itemPrototype.Name)
}
testDeleteItemPrototype(itemPrototype, t)
}