forked from infobloxopen/infoblox-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects_test.go
338 lines (275 loc) · 8.75 KB
/
objects_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
package ibclient
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"encoding/json"
)
var _ = Describe("Objects", func() {
Context("EA Object", func() {
ea := EA{
"Cloud API Owned": Bool(true),
"Tenant Name": "Engineering01",
"Maximum Wait Time": 120,
"DNS Support": Bool(false),
}
eaJSON := `{"Cloud API Owned":{"value":"True"},` +
`"Tenant Name":{"value":"Engineering01"},` +
`"Maximum Wait Time":{"value":120},` +
`"DNS Support":{"value":"False"}}`
Context("Marshalling", func() {
Context("expected JSON is returned", func() {
js, err := json.Marshal(ea)
It("should not error", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should match json expected", func() {
Expect(js).To(MatchJSON(eaJSON))
})
})
})
Context("Unmarshalling", func() {
Context("expected object is returned", func() {
var actualEA EA
err := json.Unmarshal([]byte(eaJSON), &actualEA)
It("should not error", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should match object expected", func() {
Expect(actualEA).To(Equal(ea))
})
})
})
})
Context("EA Search Object", func() {
eas := EASearch{
"Network Name": "Shared-Net",
"Network View": "Global",
}
expectedJSON := `{"*Network Name" :"Shared-Net",` +
`"*Network View" :"Global"}`
Context("Marshalling", func() {
Context("expected JSON is returned", func() {
js, err := json.Marshal(eas)
It("should not error", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should match json expected", func() {
Expect(js).To(MatchJSON(expectedJSON))
})
})
})
})
Context("EADefListValue Object", func() {
var eadListVal EADefListValue = "Host Record"
eadListValJSON := `{"value": "Host Record"}`
Context("Marshalling", func() {
Context("expected JSON is returned", func() {
js, err := json.Marshal(eadListVal)
It("should not error", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should match json expected", func() {
Expect(js).To(MatchJSON(eadListValJSON))
})
})
})
Context("Unmarshalling", func() {
Context("expected object is returned", func() {
var actualEadListVal EADefListValue
err := json.Unmarshal([]byte(eadListValJSON), &actualEadListVal)
It("should not error", func() {
Expect(err).NotTo(HaveOccurred())
})
It("should match object expected", func() {
Expect(actualEadListVal).To(Equal(eadListVal))
})
})
})
})
Context("Instantiation of", func() {
Context("NetworkView object", func() {
name := "myview"
nv := NewNetworkView(NetworkView{Name: name})
It("should set fields correctly", func() {
Expect(nv.Name).To(Equal(name))
})
It("should set base fields correctly", func() {
Expect(nv.ObjectType()).To(Equal("networkview"))
Expect(nv.ReturnFields()).To(ConsistOf("extattrs", "name"))
})
})
Context("Network object", func() {
cidr := "123.0.0.0/24"
netviewName := "localview"
nw := NewNetwork(Network{Cidr: cidr, NetviewName: netviewName})
searchEAs := EASearch{"Network Name": "shared-net"}
nw.eaSearch = searchEAs
It("should set fields correctly", func() {
Expect(nw.Cidr).To(Equal(cidr))
Expect(nw.NetviewName).To(Equal(netviewName))
})
It("should set base fields correctly", func() {
Expect(nw.ObjectType()).To(Equal("network"))
Expect(nw.ReturnFields()).To(ConsistOf("extattrs", "network", "network_view"))
Expect(nw.EaSearch()).To(Equal(searchEAs))
})
})
Context("NetworkContainer object", func() {
cidr := "74.0.8.0/24"
netviewName := "globalview"
nwc := NewNetworkContainer(NetworkContainer{Cidr: cidr, NetviewName: netviewName})
It("should set fields correctly", func() {
Expect(nwc.Cidr).To(Equal(cidr))
Expect(nwc.NetviewName).To(Equal(netviewName))
})
It("should set base fields correctly", func() {
Expect(nwc.ObjectType()).To(Equal("networkcontainer"))
Expect(nwc.ReturnFields()).To(ConsistOf("extattrs", "network", "network_view"))
})
})
Context("FixedAddress object", func() {
netviewName := "globalview"
cidr := "25.0.7.0/24"
ipAddress := "25.0.7.59/24"
mac := "11:22:33:44:55:66"
fixedAddr := NewFixedAddress(FixedAddress{
NetviewName: netviewName,
Cidr: cidr,
IPAddress: ipAddress,
Mac: mac})
It("should set fields correctly", func() {
Expect(fixedAddr.NetviewName).To(Equal(netviewName))
Expect(fixedAddr.Cidr).To(Equal(cidr))
Expect(fixedAddr.IPAddress).To(Equal(ipAddress))
Expect(fixedAddr.Mac).To(Equal(mac))
})
It("should set base fields correctly", func() {
Expect(fixedAddr.ObjectType()).To(Equal("fixedaddress"))
Expect(fixedAddr.ReturnFields()).To(ConsistOf("network_view", "network", "ipv4addr", "mac", "extattrs"))
})
})
Context("EADefinition object", func() {
comment := "Test Extensible Attribute"
flags := "CGV"
listValues := []EADefListValue{"True", "False"}
name := "Test EA"
eaType := "string"
allowedTypes := []string{"arecord", "aaarecord", "ptrrecord"}
eaDef := NewEADefinition(EADefinition{
Name: name,
Comment: comment,
Flags: flags,
ListValues: listValues,
Type: eaType,
AllowedObjectTypes: allowedTypes})
It("should set fields correctly", func() {
Expect(eaDef.Comment).To(Equal(comment))
Expect(eaDef.Flags).To(Equal(flags))
Expect(eaDef.ListValues).To(ConsistOf(listValues))
Expect(eaDef.Name).To(Equal(name))
Expect(eaDef.Type).To(Equal(eaType))
Expect(eaDef.AllowedObjectTypes).To(ConsistOf(allowedTypes))
})
It("should set base fields correctly", func() {
Expect(eaDef.ObjectType()).To(Equal("extensibleattributedef"))
Expect(eaDef.ReturnFields()).To(ConsistOf("allowed_object_types", "comment", "flags", "list_values", "name", "type"))
})
})
Context("RecordA object", func() {
ipv4addr := "1.1.1.1"
name := "bind_a.domain.com"
view := "default"
zone := "domain.com"
ra := NewRecordA(RecordA{
Ipv4Addr: ipv4addr,
Name: name,
View: view,
Zone: zone})
It("should set fields correctly", func() {
Expect(ra.Ipv4Addr).To(Equal(ipv4addr))
Expect(ra.Name).To(Equal(name))
Expect(ra.View).To(Equal(view))
Expect(ra.Zone).To(Equal(zone))
})
It("should set base fields correctly", func() {
Expect(ra.ObjectType()).To(Equal("record:a"))
Expect(ra.ReturnFields()).To(ConsistOf("extattrs", "ipv4addr", "name", "view", "zone"))
})
})
Context("RecordCNAME object", func() {
canonical := "cname.domain.com"
name := "bind_cname.domain.com"
view := "default"
zone := "domain.com"
rc := NewRecordCNAME(RecordCNAME{
Canonical: canonical,
Name: name,
View: view,
Zone: zone})
It("should set fields correctly", func() {
Expect(rc.Canonical).To(Equal(canonical))
Expect(rc.Name).To(Equal(name))
Expect(rc.View).To(Equal(view))
Expect(rc.Zone).To(Equal(zone))
})
It("should set base fields correctly", func() {
Expect(rc.ObjectType()).To(Equal("record:cname"))
Expect(rc.ReturnFields()).To(ConsistOf("extattrs", "canonical", "name", "view", "zone"))
})
})
Context("RecordTXT object", func() {
name := "txt.domain.com"
text := "this is text string"
view := "default"
zone := "domain.com"
rt := NewRecordTXT(RecordTXT{
Name: name,
Text: text,
View: view,
Zone: zone})
It("should set fields correctly", func() {
Expect(rt.Name).To(Equal(name))
Expect(rt.Text).To(Equal(text))
Expect(rt.View).To(Equal(view))
Expect(rt.Zone).To(Equal(zone))
})
It("should set base fields correctly", func() {
Expect(rt.ObjectType()).To(Equal("record:txt"))
Expect(rt.ReturnFields()).To(ConsistOf("extattrs", "name", "text", "view", "zone"))
})
})
Context("ZoneAuth object", func() {
fqdn := "domain.com"
view := "default"
za := NewZoneAuth(ZoneAuth{
Fqdn: fqdn,
View: view})
It("should set fields correctly", func() {
Expect(za.Fqdn).To(Equal(fqdn))
Expect(za.View).To(Equal(view))
})
It("should set base fields correctly", func() {
Expect(za.ObjectType()).To(Equal("zone_auth"))
Expect(za.ReturnFields()).To(ConsistOf("extattrs", "fqdn", "view"))
})
})
})
Context("Unmarshalling malformed JSON", func() {
Context("for EA", func() {
badJSON := `""`
var ea EA
err := json.Unmarshal([]byte(badJSON), &ea)
It("should return an error", func() {
Expect(err).ToNot(BeNil())
})
})
Context("for EADefListValue", func() {
badJSON := `""`
var ead EADefListValue
err := json.Unmarshal([]byte(badJSON), &ead)
It("should return an error", func() {
Expect(err).ToNot(BeNil())
})
})
})
})