forked from claranet/go-zabbix-api
-
Notifications
You must be signed in to change notification settings - Fork 2
/
application_test.go
79 lines (65 loc) · 1.77 KB
/
application_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
package zabbix_test
import (
"fmt"
"math/rand"
"reflect"
"testing"
zapi "github.com/claranet/go-zabbix-api"
)
func testCreateApplication(host *zapi.Host, t *testing.T) *zapi.Application {
apps := zapi.Applications{{HostID: host.HostID, Name: fmt.Sprintf("App %d for %s", rand.Int(), host.Host)}}
err := testGetAPI(t).ApplicationsCreate(apps)
if err != nil {
t.Fatal(err)
}
return &apps[0]
}
func testDeleteApplication(app *zapi.Application, t *testing.T) {
err := testGetAPI(t).ApplicationsDelete(zapi.Applications{*app})
if err != nil {
t.Fatal(err)
}
}
func TestApplications(t *testing.T) {
skipTestIfVersionGreaterThanOrEqual(t, "5.4", "dropped support for Application API")
api := testGetAPI(t)
group := testCreateHostGroup(t)
defer testDeleteHostGroup(group, t)
host := testCreateHost(group, t)
defer testDeleteHost(host, t)
app := testCreateApplication(host, t)
if app.ApplicationID == "" {
t.Errorf("Id is empty: %#v", app)
}
app2 := testCreateApplication(host, t)
if app2.ApplicationID == "" {
t.Errorf("Id is empty: %#v", app2)
}
if reflect.DeepEqual(app, app2) {
t.Errorf("Apps are equal:\n%#v\n%#v", app, app2)
}
apps, err := api.ApplicationsGet(zapi.Params{"hostids": host.HostID})
if err != nil {
t.Fatal(err)
}
if len(apps) != 2 {
t.Errorf("Failed to create apps: %#v", apps)
}
app2, err = api.ApplicationGetByID(app.ApplicationID)
if err != nil {
t.Fatal(err)
}
app2.TemplateID = ""
if !reflect.DeepEqual(app, app2) {
t.Errorf("Apps are not equal:\n%#v\n%#v", app, app2)
}
app2, err = api.ApplicationGetByHostIDAndName(host.HostID, app.Name)
if err != nil {
t.Fatal(err)
}
app2.TemplateID = ""
if !reflect.DeepEqual(app, app2) {
t.Errorf("Apps are not equal:\n%#v\n%#v", app, app2)
}
testDeleteApplication(app, t)
}