This repository has been archived by the owner on Apr 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 103
/
application_test.go
76 lines (64 loc) · 1.57 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
package zabbix_test
import (
. "."
"fmt"
"math/rand"
"reflect"
"testing"
)
func CreateApplication(host *Host, t *testing.T) *Application {
apps := Applications{{HostId: host.HostId, Name: fmt.Sprintf("App %d for %s", rand.Int(), host.Host)}}
err := getAPI(t).ApplicationsCreate(apps)
if err != nil {
t.Fatal(err)
}
return &apps[0]
}
func DeleteApplication(app *Application, t *testing.T) {
err := getAPI(t).ApplicationsDelete(Applications{*app})
if err != nil {
t.Fatal(err)
}
}
func TestApplications(t *testing.T) {
api := getAPI(t)
group := CreateHostGroup(t)
defer DeleteHostGroup(group, t)
host := CreateHost(group, t)
defer DeleteHost(host, t)
app := CreateApplication(host, t)
if app.ApplicationId == "" {
t.Errorf("Id is empty: %#v", app)
}
app2 := CreateApplication(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(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)
}
DeleteApplication(app, t)
}