-
Notifications
You must be signed in to change notification settings - Fork 15
/
hostinterface_test.go
109 lines (83 loc) · 2.44 KB
/
hostinterface_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
107
108
109
package zabbix
import (
"reflect"
"testing"
)
const (
testHostinterfaceIP = "10.1.1.2"
testHostinterfacePort = "10151"
)
func TestHostinterfaceCRUD(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)
tCreatedIDs := testTemplateCreate(t, z, hgCreatedIDs)
defer testTemplateDelete(t, z, tCreatedIDs)
hCreatedIDs := testHostCreate(t, z, hgCreatedIDs, tCreatedIDs)
defer testHostDelete(t, z, hCreatedIDs)
// Create and delete
hiCreatedIDs := testHostinterfaceCreate(t, z, hCreatedIDs[0])
defer testHostinterfaceDelete(t, z, hiCreatedIDs)
// Get
testHostinterfaceGet(t, z, hCreatedIDs)
}
func testHostinterfaceCreate(t *testing.T, z Context, hCreatedID int) []int {
hiCreatedIDs, _, err := z.HostinterfaceCreate([]HostinterfaceObject{
{
HostID: hCreatedID,
IP: testHostinterfaceIP,
Main: HostinterfaceMainNotDefault,
Port: testHostinterfacePort,
Type: HostinterfaceTypeAgent,
UseIP: HostinterfaceUseipIP,
},
})
if err != nil {
t.Fatal("Hostinterface create error:", err)
}
if len(hiCreatedIDs) == 0 {
t.Fatal("Hostinterface create error: empty IDs array")
}
t.Logf("Hostinterface create: success")
return hiCreatedIDs
}
func testHostinterfaceDelete(t *testing.T, z Context, hiCreatedIDs []int) []int {
hiDeletedIDs, _, err := z.HostinterfaceDelete(hiCreatedIDs)
if err != nil {
t.Fatal("Hostinterface delete error:", err)
}
if len(hiDeletedIDs) == 0 {
t.Fatal("Hostinterface delete error: empty IDs array")
}
if reflect.DeepEqual(hiDeletedIDs, hiCreatedIDs) == false {
t.Fatal("Hostinterface delete error: IDs arrays for created and deleted hostinterface are mismatch")
}
t.Logf("Hostinterface delete: success")
return hiDeletedIDs
}
func testHostinterfaceGet(t *testing.T, z Context, hCreatedIDs []int) []HostinterfaceObject {
hiObjects, _, err := z.HostinterfaceGet(HostinterfaceGetParams{
SelectHosts: SelectExtendedOutput,
HostIDs: hCreatedIDs,
GetParameters: GetParameters{
Filter: map[string]interface{}{
"ip": testHostinterfaceIP,
},
Output: SelectExtendedOutput,
},
})
if err != nil {
t.Error("Hostinterface get error:", err)
} else {
if len(hiObjects) == 0 {
t.Error("Hostinterface get error: unable to find created hostinterface")
} else {
t.Logf("Hostinterface get: success")
}
}
return hiObjects
}