This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventory_test.go
113 lines (91 loc) · 2 KB
/
inventory_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
110
111
112
113
package goh4
import "testing"
func TestInventorySearch(t *testing.T) {
t.Log("Starting InventorySearch Test")
hostname := "collectorDatamover-1"
scope := "Tetration"
h := setupH4()
var f0 Filter
f0.Type = "contains"
f0.Field = "host_name"
f0.Value = hostname
// define a filter
f := &QueryFilter{
Type: "and",
Filters: []interface{}{&f0},
}
// define a search
s := &InventoryQuery{
Limit: 100,
Scope: scope,
Filter: f,
}
res, err := h.InventorySearch(s)
if err != nil {
t.Errorf("Error in InventorySearch: %s", err.Error())
return
}
if len(res) != 1 {
t.Errorf("Invalid array length, expecting 1, got %d\n", len(res))
return
}
if res[0].Hostname != hostname {
t.Errorf("Invalid hostname, expecting %s, got %s\n", hostname, res[0].Hostname)
return
}
}
func TestInventorySearchEmpty(t *testing.T) {
t.Log("Starting InventorySearch Test - Empty Results")
hostname := "collectorDatamover-X"
scope := "Tetration"
h := setupH4()
var f0 Filter
f0.Type = "contains"
f0.Field = "host_name"
f0.Value = hostname
// define a filter
f := &QueryFilter{
Type: "and",
Filters: []interface{}{&f0},
}
// define a search
s := &InventoryQuery{
Limit: 100,
Scope: scope,
Filter: f,
}
res, err := h.InventorySearch(s)
if err != nil {
t.Errorf("Error in InventorySearch: %s", err.Error())
}
if len(res) != 0 {
t.Errorf("Invalid array length, expecting 0, got %d\n", len(res))
return
}
}
func TestInventorySearchInvalid(t *testing.T) {
t.Log("Starting InventorySearch Test - Invalid Request")
hostname := "collectorDatamover-X"
scope := "Tetration"
h := setupH4()
var f0 Filter
f0.Type = "contains"
f0.Field = "host_name"
f0.Value = hostname
// define a filter
f := &QueryFilter{
Type: "bob",
Filters: []interface{}{&f0},
}
// define a search
s := &InventoryQuery{
Limit: 100,
Scope: scope,
Filter: f,
}
_, err := h.InventorySearch(s)
if err == nil {
t.Error("No Error returned for TestInventorySearchInvalid")
return
}
}