-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathobject_manager_dtc_lbdn_test.go
415 lines (372 loc) · 15.7 KB
/
object_manager_dtc_lbdn_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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
package ibclient
import (
"fmt"
"github.com/infobloxopen/infoblox-go-client/v2/utils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Object Manager: Dtc Lbdn", func() {
Describe("Create Dtc Lbdn with minimum params", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test lbdn"
disable := false
autoConsolidatedMonitors := false
name := "TestLbdn1"
fakeRefReturn := fmt.Sprintf("dtc:lbdn/ZG5zLmhvc3QkLZhd3QuaDE:%s", name)
lbMethod := "ROUND_ROBIN"
patterns := []string{"*info.com"}
persistence := uint32(60)
priority := uint32(1)
topology := ""
types := []string{"A", "CNAME"}
ttl := uint32(60)
useTtl := true
conn := &fakeConnector{
createObjectObj: NewDtcLbdn("", name, nil, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, topology, types, ttl, useTtl),
getObjectObj: &DtcLbdn{},
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewDtcLbdn("", name, nil, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, topology, types, ttl, useTtl),
fakeRefReturn: fakeRefReturn,
}
conn.resultObject.(*DtcLbdn).Ref = fakeRefReturn
objMgr := NewObjectManager(conn, cmpType, tenantID)
It("should pass expected DtcLbdn Object to CreateObject", func() {
actualRecord, err := objMgr.CreateDtcLbdn(name, nil, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, topology, types, ttl, useTtl)
Expect(actualRecord).To(Equal(conn.resultObject))
Expect(err).To(BeNil())
})
It("should fail to create a DTC lbdn object", func() {
actualRecord, err := objMgr.CreateDtcLbdn("", nil, comment, disable, autoConsolidatedMonitors, nil, "", patterns, persistence, nil, priority, topology, types, ttl, useTtl)
Expect(actualRecord).To(BeNil())
Expect(err).ToNot(BeNil())
})
})
Describe("Get Dtc Lbdn", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test lbdn"
disable := false
autoConsolidatedMonitors := false
name := "TestLbdn1"
fakeRefReturn := fmt.Sprintf("dtc:lbdn/ZG5zLmhvc3QkLZhd3QuaDE:%s", name)
lbMethod := "ROUND_ROBIN"
patterns := []string{"*info.com"}
persistence := uint32(60)
priority := uint32(1)
topology := ""
types := []string{"A", "CNAME"}
ttl := uint32(60)
useTtl := true
queryParams := NewQueryParams(false, map[string]string{"name": name})
res := NewDtcLbdn("", name, nil, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, topology, types, ttl, useTtl)
conn := &fakeConnector{
getObjectObj: NewEmptyDtcLbdn(),
resultObject: []DtcLbdn{*res},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
It("should get expected DtcLbdn Object from getObject", func() {
conn.getObjectQueryParams = queryParams
actualRecord, err := objMgr.GetAllDtcLbdn(queryParams)
Expect(actualRecord).To(Equal(conn.resultObject))
Expect(err).To(BeNil())
})
It("should fail to get expected DtcLbdn Object from getObject", func() {
queryParams1 := NewQueryParams(false, map[string]string{"name": "test-lbdn111"})
conn.getObjectQueryParams = queryParams1
conn.resultObject = []DtcLbdn{}
actualRecord, err := objMgr.GetAllDtcLbdn(queryParams1)
Expect(actualRecord).To(Equal(conn.resultObject))
Expect(err).To(BeNil())
})
})
Describe("Get Dtc Lbdn: Negative scenario", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
queryParams2 := NewQueryParams(false, map[string]string{"lb_method": "ROUND_ROBIN"})
conn := &fakeConnector{
getObjectObj: NewEmptyDtcLbdn(),
getObjectQueryParams: queryParams2,
resultObject: []DtcLbdn{},
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
// negative scenario
conn.getObjectError = fmt.Errorf("Field is not searchable: lb_method")
It("should fail to get expected DtcLbdn Object from getObject with non searchable field", func() {
_, err := objMgr.GetAllDtcLbdn(queryParams2)
Expect(err).ToNot(BeNil())
})
})
Describe("Get Dtc Lbdn by name", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test lbdn"
disable := false
autoConsolidatedMonitors := false
name := "TestLbdn11"
fakeRefReturn := fmt.Sprintf("dtc:lbdn/ZG5zLmhvc3QkLZhd3QuaDE:%s", name)
lbMethod := "ROUND_ROBIN"
patterns := []string{"*info.com"}
persistence := uint32(60)
priority := uint32(1)
topology := ""
types := []string{"A", "CNAME"}
ttl := uint32(60)
useTtl := true
queryParams := NewQueryParams(false, map[string]string{"name": name})
res := NewDtcLbdn(fakeRefReturn, name, nil, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, topology, types, ttl, useTtl)
conn := &fakeConnector{
getObjectObj: NewEmptyDtcLbdn(),
getObjectQueryParams: NewQueryParams(false, map[string]string{"name": name}),
resultObject: []DtcLbdn{*res},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
It("should get expected DtcLbdn Object from getObject", func() {
conn.getObjectQueryParams = queryParams
actualRecord, err := objMgr.GetDtcLbdn(name)
Expect(*actualRecord).To(Equal(conn.resultObject.([]DtcLbdn)[0]))
Expect(err).To(BeNil())
})
})
Describe("Get Dtc Lbdn by name, nagative scenario", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
conn := &fakeConnector{
getObjectRef: "",
getObjectObj: NewEmptyDtcLbdn(),
getObjectQueryParams: NewQueryParams(false, map[string]string{"name": ""}),
getObjectError: fmt.Errorf("name of the record is required to retrieve a unique DtcLbdn record"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord, expectedObj *DtcLbdn
var err error
expectedObj = nil
It("should pass expected Dtc Lbdn record Object to Getobject", func() {
actualRecord, err = objMgr.GetDtcLbdn("")
})
It("should return expected Dtc Lbdn record Object", func() {
Expect(actualRecord).To(Equal(expectedObj))
Expect(err).To(Equal(conn.getObjectError))
})
})
Describe("Create Dtc Lbdn with maximum parameters", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test lbdn"
disable := false
autoConsolidatedMonitors := false
name := "TestLbdn1"
fakeRefReturn := fmt.Sprintf("dtc:lbdn/ZG5zLmhvc3QkLZhd3QuaDE:%s", name)
lbMethod := "TOPOLOGY"
patterns := []string{"*info.com"}
persistence := uint32(60)
pools := []*DtcPoolLink{{Pool: "test-pool", Ratio: 3}}
priority := uint32(1)
topology := "test-topo"
types := []string{"A", "CNAME"}
ttl := uint32(60)
useTtl := true
poolRef := "dtc:pool/ZG5zLmhvc3QkLmNvbS5hcGkudjI6dGVzdC1wb29s:test-pool"
topologyRef := "dtc:topology/ZG5zLmhvc3QkLmNvbS5hcGkudjI6dGVzdC1wb29s:test-topo"
createObjPools := []*DtcPoolLink{{Pool: poolRef, Ratio: 3}}
zone := "test-zone"
zones := []string{zone}
zoneRef := "zone_auth/ZG5zLmhvc3QkLmNvbS5hcGkudjI6dGVzdC1wb29s:test-zone"
zoneAuth := []*ZoneAuth{{Ref: zoneRef, Fqdn: zone}}
conn := &fakeConnector{
createObjectObj: NewDtcLbdn("", name, zoneAuth, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, createObjPools, priority, topologyRef, types, ttl, useTtl),
getObjectObj: map[string]interface{}{
"DtcPool": &DtcPool{},
"DtcTopology": &DtcTopology{},
"ZoneAuth": &ZoneAuth{},
},
getObjectQueryParams: map[string]*QueryParams{
"DtcPool": NewQueryParams(false, map[string]string{"name": "test-pool"}),
"DtcTopology": NewQueryParams(false, map[string]string{"name": "test-topo"}),
"ZoneAuth": NewQueryParams(false, map[string]string{"fqdn": "test-zone"}),
},
resultObject: map[string]interface{}{
"DtcPool": []DtcPool{{
Ref: poolRef,
Name: utils.StringPtr("test-pool"),
}},
"DtcTopology": []DtcTopology{{
Ref: topologyRef,
Name: utils.StringPtr("test-topo"),
}},
"DtcLbdn": NewDtcLbdn(fakeRefReturn, name, zoneAuth, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, createObjPools, priority, topologyRef, types, ttl, useTtl),
"ZoneAuth": []ZoneAuth{{
Ref: zoneRef,
Fqdn: zone,
}},
},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
It("should pass expected DtcLbdn Object to CreateObject", func() {
actualRecord, err := objMgr.CreateDtcLbdn(name, zones, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, pools, priority, topology, types, ttl, useTtl)
Expect(actualRecord).To(Equal(conn.resultObject.(map[string]interface{})["DtcLbdn"]))
Expect(err).To(BeNil())
})
})
Describe("Delete Dtc Lbdn", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
recordName := "test-lbdn"
deleteRef := fmt.Sprintf("dtc:lbdn/ZG5zLmJpbmRfY25h:%s/%20%20", recordName)
nwFakeConnector := &fakeConnector{
deleteObjectRef: deleteRef,
fakeRefReturn: deleteRef,
}
objMgr := NewObjectManager(nwFakeConnector, cmpType, tenantID)
var actualRef string
var err error
It("should pass expected DTC Lbdn Ref to DeleteObject", func() {
actualRef, err = objMgr.DeleteDtcLbdn(deleteRef)
})
It("should return expected DTC Lbdn Ref", func() {
Expect(actualRef).To(Equal(deleteRef))
Expect(err).To(BeNil())
})
It("should pass expected DTC Lbdn Ref to DeleteObject", func() {
deleteRef2 := "dtc:lbdn"
nwFakeConnector.deleteObjectRef = deleteRef2
nwFakeConnector.fakeRefReturn = ""
nwFakeConnector.deleteObjectError = fmt.Errorf("not found")
actualRef, err = objMgr.DeleteDtcLbdn(deleteRef2)
})
It("should return an error", func() {
Expect(err).ToNot(BeNil())
})
})
Describe("Update Dtc Lbdn", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
disable := false
autoConsolidatedMonitors := false
lbMethod := "RATIO"
patterns := []string{"*info.com"}
persistence := uint32(60)
priority := uint32(1)
types := []string{"A", "CNAME"}
ttl := uint32(60)
useTtl := true
name1 := "TestLbdn222"
comment1 := "test lbdn comment updated"
updateRef := fmt.Sprintf("dtc:lbdn/ZG5zLmhvc3QkLZhd3QuaDE:%s", name1)
conn := &fakeConnector{
getObjectObj: NewEmptyDtcLbdn(),
getObjectRef: updateRef,
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewDtcLbdn(updateRef, name1, nil, comment1, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, "", types, ttl, useTtl),
fakeRefReturn: updateRef,
updateObjectObj: NewDtcLbdn(updateRef, name1, nil, comment1, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, "", types, ttl, useTtl),
updateObjectRef: updateRef,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
It("should pass expected DtcLbdn Object to UpdateObject", func() {
actualRecord, err := objMgr.UpdateDtcLbdn(updateRef, name1, nil, comment1, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, "", types, ttl, useTtl)
Expect(actualRecord).To(Equal(conn.resultObject))
Expect(err).To(BeNil())
})
})
Describe("Update Dtc Lbdn with maximum params", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test lbdn"
disable := false
autoConsolidatedMonitors := false
name := "TestLbdn1"
fakeRefReturn := fmt.Sprintf("dtc:lbdn/ZG5zLmhvc3QkLZhd3QuaDE:%s", name)
initLbMethod := "RATIO"
lbMethod := "TOPOLOGY"
patterns := []string{"*info.com"}
persistence := uint32(60)
pools := []*DtcPoolLink{{Pool: "test-pool", Ratio: 3}}
priority := uint32(1)
topology := "test-topo"
types := []string{"A", "CNAME"}
ttl := uint32(60)
useTtl := true
poolRef := "dtc:pool/ZG5zLmhvc3QkLmNvbS5hcGkudjI6dGVzdC1wb29s:test-pool"
topologyRef := "dtc:topology/ZG5zLmhvc3QkLmNvbS5hcGkudjI6dGVzdC1wb29s:test-topo"
createObjPools := []*DtcPoolLink{{Pool: poolRef, Ratio: 3}}
zone := "test-zone"
zones := []string{zone}
zoneRef := "zone_auth/ZG5zLmhvc3QkLmNvbS5hcGkudjI6dGVzdC1wb29s:test-zone"
zoneAuth := []*ZoneAuth{{Ref: zoneRef, Fqdn: zone}}
initObject := NewDtcLbdn("", name, nil, comment, disable, autoConsolidatedMonitors, nil, initLbMethod, patterns, persistence, nil, priority, "", types, ttl, useTtl)
initObject.Ref = fakeRefReturn
conn := &fakeConnector{
getObjectObj: map[string]interface{}{
"DtcPool": &DtcPool{},
"DtcTopology": &DtcTopology{},
"ZoneAuth": &ZoneAuth{},
},
getObjectQueryParams: map[string]*QueryParams{
"DtcPool": NewQueryParams(false, map[string]string{"name": "test-pool"}),
"DtcTopology": NewQueryParams(false, map[string]string{"name": "test-topo"}),
"ZoneAuth": NewQueryParams(false, map[string]string{"fqdn": "test-zone"}),
},
updateObjectRef: fakeRefReturn,
updateObjectObj: NewDtcLbdn(fakeRefReturn, name, zoneAuth, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, createObjPools, priority, topologyRef, types, ttl, useTtl),
resultObject: map[string]interface{}{
"DtcPool": []DtcPool{{
Ref: poolRef,
Name: utils.StringPtr("test-pool"),
}},
"DtcTopology": []DtcTopology{{
Ref: topologyRef,
Name: utils.StringPtr("test-topo"),
}},
"DtcLbdn": NewDtcLbdn(fakeRefReturn, name, zoneAuth, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, createObjPools, priority, topologyRef, types, ttl, useTtl),
"ZoneAuth": []ZoneAuth{{
Ref: zoneRef,
Fqdn: zone,
}},
},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
It("should pass expected DtcLbdn Object to CreateObject", func() {
actualRecord, err := objMgr.UpdateDtcLbdn(fakeRefReturn, name, zones, comment, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, pools, priority, topology, types, ttl, useTtl)
Expect(actualRecord).To(Equal(conn.resultObject.(map[string]interface{})["DtcLbdn"]))
Expect(err).To(BeNil())
})
})
Describe("Update Dtc Lbdn with, negative scenario", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
disable := false
autoConsolidatedMonitors := false
lbMethod := "RATIO"
patterns := []string{"*info.com"}
persistence := uint32(60)
priority := uint32(1)
types := []string{"A", "CNAME"}
ttl := uint32(60)
useTtl := true
name2 := "test-LBDN122"
comment2 := "comment updated"
oldRef := "dtc:lbdn/ZG5zLmhvc3QkLZhd3QuaDE:test-lbdn121"
conn := &fakeConnector{
getObjectObj: NewEmptyDtcLbdn(),
getObjectRef: oldRef,
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewDtcLbdn(oldRef, name2, nil, comment2, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, "", types, ttl, useTtl),
getObjectError: fmt.Errorf("not found"),
fakeRefReturn: oldRef,
updateObjectObj: NewDtcLbdn(oldRef, name2, nil, comment2, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, "", types, ttl, useTtl),
updateObjectRef: oldRef,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
// negative scenario
It("should fail to update DtcLbdn Object", func() {
actualRecord, err := objMgr.UpdateDtcLbdn(oldRef, name2, nil, comment2, disable, autoConsolidatedMonitors, nil, lbMethod, patterns, persistence, nil, priority, "", types, ttl, useTtl)
Expect(actualRecord).To(BeNil())
Expect(err).ToNot(BeNil())
})
})
})