forked from nixys/nxs-go-zabbix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mediatype_test.go
107 lines (84 loc) · 2.32 KB
/
mediatype_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
package zabbix
import (
"reflect"
"testing"
)
const (
testMediatypeName = "testMediatypeName"
testMediatypeDescription = "testMediatypeDescription"
testMediatypeExecPath = "test_script.sh"
)
func TestMediatypeCRUD(t *testing.T) {
var z Context
// Login
loginTest(&z, t)
defer logoutTest(&z, t)
// Create and delete
mtCreatedIDs := testMediatypeCreate(t, z)
defer testMediatypeDelete(t, z, mtCreatedIDs)
// Get
testMediatypeGet(t, z, mtCreatedIDs)
}
func testMediatypeCreate(t *testing.T, z Context) []int {
hiCreatedIDs, _, err := z.MediatypeCreate([]MediatypeObject{
{
Name: testMediatypeName,
Description: testMediatypeDescription,
Type: MediatypeScript,
ExecPath: testMediatypeExecPath,
MessageTemplates: []MediatypeMessageTemplateObject{
{
EventSource: MediatypeMessageTemplateEventSourceTriggers,
Recovery: MediatypeMessageTemplateRecoveryOperations,
Subject: "SSS",
Message: "MMM",
},
},
},
})
if err != nil {
t.Fatal("Mediatype create error:", err)
}
if len(hiCreatedIDs) == 0 {
t.Fatal("Mediatype create error: empty IDs array")
}
t.Logf("Mediatype create: success")
return hiCreatedIDs
}
func testMediatypeDelete(t *testing.T, z Context, mtCreatedIDs []int) []int {
mtDeletedIDs, _, err := z.MediatypeDelete(mtCreatedIDs)
if err != nil {
t.Fatal("Mediatype delete error:", err)
}
if len(mtDeletedIDs) == 0 {
t.Fatal("Mediatype delete error: empty IDs array")
}
if reflect.DeepEqual(mtDeletedIDs, mtCreatedIDs) == false {
t.Fatal("Mediatype delete error: IDs arrays for created and deleted mediatype are mismatch")
}
t.Logf("Mediatype delete: success")
return mtDeletedIDs
}
func testMediatypeGet(t *testing.T, z Context, mtCreatedIDs []int) []MediatypeObject {
mtObjects, _, err := z.MediatypeGet(MediatypeGetParams{
SelectUsers: SelectExtendedOutput,
MediatypeIDs: mtCreatedIDs,
GetParameters: GetParameters{
Filter: map[string]interface{}{
"name": testMediatypeName,
"exec_path": testMediatypeExecPath,
},
Output: SelectExtendedOutput,
},
})
if err != nil {
t.Error("Mediatype get error:", err)
} else {
if len(mtObjects) == 0 {
t.Error("Mediatype get error: unable to find created mediatype")
} else {
t.Logf("Mediatype get: success")
}
}
return mtObjects
}