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
/
host_test.go
89 lines (76 loc) · 1.73 KB
/
host_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
package zabbix_test
import (
. "."
"fmt"
"math/rand"
"reflect"
"testing"
)
func CreateHost(group *HostGroup, t *testing.T) *Host {
name := fmt.Sprintf("%s-%d", getHost(), rand.Int())
iface := HostInterface{DNS: name, Port: "42", Type: Agent, UseIP: 0, Main: 1}
hosts := Hosts{{
Host: name,
Name: "Name for " + name,
GroupIds: HostGroupIds{{group.GroupId}},
Interfaces: HostInterfaces{iface},
}}
err := getAPI(t).HostsCreate(hosts)
if err != nil {
t.Fatal(err)
}
return &hosts[0]
}
func DeleteHost(host *Host, t *testing.T) {
err := getAPI(t).HostsDelete(Hosts{*host})
if err != nil {
t.Fatal(err)
}
}
func TestHosts(t *testing.T) {
api := getAPI(t)
group := CreateHostGroup(t)
defer DeleteHostGroup(group, t)
hosts, err := api.HostsGetByHostGroups(HostGroups{*group})
if err != nil {
t.Fatal(err)
}
if len(hosts) != 0 {
t.Errorf("Bad hosts: %#v", hosts)
}
host := CreateHost(group, t)
if host.HostId == "" || host.Host == "" {
t.Errorf("Something is empty: %#v", host)
}
host.GroupIds = nil
host.Interfaces = nil
host2, err := api.HostGetByHost(host.Host)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(host, host2) {
t.Errorf("Hosts are not equal:\n%#v\n%#v", host, host2)
}
host2, err = api.HostGetById(host.HostId)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(host, host2) {
t.Errorf("Hosts are not equal:\n%#v\n%#v", host, host2)
}
hosts, err = api.HostsGetByHostGroups(HostGroups{*group})
if err != nil {
t.Fatal(err)
}
if len(hosts) != 1 {
t.Errorf("Bad hosts: %#v", hosts)
}
DeleteHost(host, t)
hosts, err = api.HostsGetByHostGroups(HostGroups{*group})
if err != nil {
t.Fatal(err)
}
if len(hosts) != 0 {
t.Errorf("Bad hosts: %#v", hosts)
}
}