forked from infobloxopen/infoblox-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_manager_aaaa-record_test.go
266 lines (235 loc) · 8.74 KB
/
object_manager_aaaa-record_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
package ibclient
import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Object Manager: AAAA-record", func() {
Describe("Allocate specific AAAA Record ", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
ipAddr := "2001:db8:abcd:14::1"
vmID := "93f9249abc039284"
vmName := "dummyvm"
dnsView := "default"
recordName := "test.domain.com"
comment := "Test creation"
fakeRefReturn := fmt.Sprintf("record:aaaa/ZG5zLmJpbmRfY25h:%s/%20%20", recordName)
ea := EA{"VM Name": vmName, "VM ID": vmID}
conn := &fakeConnector{
createObjectObj: NewRecordAAAA(
dnsView, recordName, ipAddr, false, 0, comment, ea, ""),
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyRecordAAAA(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewRecordAAAA(
dnsView, recordName, ipAddr, false, 0, comment, ea, fakeRefReturn),
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord *RecordAAAA
var err error
It("should pass expected AAAA record Object to CreateObject", func() {
actualRecord, err = objMgr.CreateAAAARecord("", dnsView, recordName, "", ipAddr, false, uint32(0), comment, ea)
})
It("should return expected AAAA record Object", func() {
Expect(actualRecord).To(Equal(conn.resultObject))
Expect(err).To(BeNil())
})
})
Describe("Allocate next available AAAA Record ", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
netviewName := "private"
cidr := "2001:db8:abcd:14::/64"
ipAddr := fmt.Sprintf("func:nextavailableip:%s,%s", cidr, netviewName)
vmID := "93f9249abc039284"
vmName := "dummyvm"
dnsView := "default"
recordName := "test.domain.com"
comment := "Test creation"
fakeRefReturn := fmt.Sprintf("record:aaaa/ZG5zLmJpbmRfY25h:%s/%20%20", recordName)
ea := EA{"VM Name": vmName, "VM ID": vmID}
conn := &fakeConnector{
createObjectObj: NewRecordAAAA(
dnsView, recordName, ipAddr, false, 0, comment, ea, ""),
getObjectRef: fakeRefReturn,
getObjectObj: NewEmptyRecordAAAA(),
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewRecordAAAA(
dnsView, recordName, ipAddr, false, 0, comment, ea, fakeRefReturn),
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord *RecordAAAA
var err error
It("should pass expected AAAA record Object to CreateObject", func() {
actualRecord, err = objMgr.CreateAAAARecord(netviewName, dnsView, recordName, cidr, "", false, uint32(0), comment, ea)
})
It("should return expected AAAA record Object", func() {
Expect(actualRecord).To(Equal(conn.resultObject))
Expect(err).To(BeNil())
})
})
Describe("Negative case: returns an error message when an IPv4 address is passed", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
netviewName := "private"
cidr := "10.0.0./24"
ipAddr := fmt.Sprintf("func:nextavailableip:%s,%s", cidr, netviewName)
vmID := "93f9249abc039284"
vmName := "dummyvm"
dnsView := "default"
recordName := "test.domain.com"
comment := "Test creation"
ea := EA{"VM Name": vmName, "VM ID": vmID}
conn := &fakeConnector{
createObjectObj: NewRecordAAAA(
dnsView, recordName, ipAddr, false, 0, comment, ea, ""),
createObjectError: fmt.Errorf("cannot parse CIDR value: invalid CIDR address: 10.0.0./24"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord, expectedObj *RecordAAAA
var err error
It("should pass expected AAAA record Object to CreateObject", func() {
actualRecord, err = objMgr.CreateAAAARecord(netviewName, dnsView, recordName, cidr, "", false, uint32(0), comment, ea)
})
It("should return expected AAAA record Object", func() {
Expect(actualRecord).To(Equal(expectedObj))
Expect(err).To(Equal(conn.createObjectError))
})
})
Describe("Get AAAA record", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
dnsView := "default"
recordName := "test.domain.com"
ipAddr := "2001:db8:abcd:14::1"
fakeRefReturn := fmt.Sprintf("record:aaaa/ZG5zLmJpbmRfY25h:%s/default", recordName)
queryParams := NewQueryParams(
false,
map[string]string{
"view": dnsView,
"name": recordName,
"ipv6addr": ipAddr,
})
conn := &fakeConnector{
getObjectRef: "",
getObjectObj: NewEmptyRecordAAAA(),
getObjectQueryParams: queryParams,
resultObject: []RecordAAAA{*NewRecordAAAA(dnsView, recordName, ipAddr, false, 0, "", nil, fakeRefReturn)},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
conn.resultObject.([]RecordAAAA)[0].Ipv6Addr = &ipAddr
var actualRecord *RecordAAAA
var err error
It("should pass expected AAAA record Object to GetObject", func() {
actualRecord, err = objMgr.GetAAAARecord(dnsView, recordName, ipAddr)
})
It("should return expected AAAA record Object", func() {
Expect(*actualRecord).To(Equal(conn.resultObject.([]RecordAAAA)[0]))
Expect(err).To(BeNil())
})
})
Describe("Negative case: returns an error when all the required fields are not passed", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
recordName := "test.domain.com"
ipAddr := "2001:db8:abcd:14::1"
fakeRefReturn := fmt.Sprintf("record:aaaa/ZG5zLmJpbmRfY25h:%s/default", recordName)
queryParams := NewQueryParams(
false,
map[string]string{
"name": recordName,
"ipv6addr": ipAddr,
})
conn := &fakeConnector{
getObjectRef: "",
getObjectObj: NewEmptyRecordAAAA(),
getObjectQueryParams: queryParams,
fakeRefReturn: fakeRefReturn,
getObjectError: fmt.Errorf("DNS view, IPv6 address and record name of the record are required to retreive a unique AAAA record"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord, expectedObj *RecordAAAA
var err error
It("should pass expected AAAA record Object to GetObject", func() {
actualRecord, err = objMgr.GetAAAARecord("", recordName, ipAddr)
})
It("should return expected AAAA record Object", func() {
Expect(actualRecord).To(Equal(expectedObj))
Expect(err).To(Equal(conn.getObjectError))
})
})
Describe("Update AAAA-record, literal value", func() {
var (
err error
objMgr IBObjectManager
conn *fakeConnector
)
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
dnsView := "default"
recordName := "test.domain.com"
refBase := "ZG5zLm5ldHdvcmtfdmlldyQyMw"
initIpAddr := "2001:db8:abcd:12::1"
initUseTtl := true
newRecordName := "test1.domain.com"
newIpAddr := "2001:db8:abcd:12::2"
newTtl := uint32(0)
newUseTtl := false
It("Negative case: updating an AAAA-record which does not exist", func() {
initRef := fmt.Sprintf(
"record:aaaa/%s:%s/%s",
refBase, recordName, dnsView)
getObjIn := NewEmptyRecordAAAA()
conn = &fakeConnector{
getObjectObj: getObjIn,
getObjectQueryParams: NewQueryParams(false, nil),
getObjectRef: initRef,
getObjectError: fmt.Errorf("test error"),
resultObject: NewEmptyRecordAAAA(),
fakeRefReturn: "",
}
objMgr = NewObjectManager(conn, cmpType, tenantID)
_, err = objMgr.UpdateAAAARecord(initRef, "", newRecordName, "", newIpAddr, newUseTtl, newTtl, "some comment", nil)
Expect(err).ToNot(BeNil())
})
It("Negative case: updating an AAAA-record with no update access", func() {
initRef := fmt.Sprintf(
"record:aaaa/%s:%s/%s",
refBase, recordName, dnsView)
initialEas := EA{
"ea0": "ea0_old_value",
"ea1": "ea1_old_value",
"ea3": "ea3_value",
"ea4": "ea4_value",
"ea5": "ea5_old_value"}
initComment := "initial comment"
initObj := NewRecordAAAA(dnsView, recordName, initIpAddr, initUseTtl, newTtl, initComment, initialEas, initRef)
getObjIn := NewEmptyRecordAAAA()
newEas := EA{
"ea0": "ea0_old_value",
"ea1": "ea1_new_value",
"ea2": "ea2_new_value",
"ea5": "ea5_old_value"}
newComment := "test comment 1"
updateObjIn := NewRecordAAAA("", newRecordName, newIpAddr, newUseTtl, newTtl, newComment, newEas, initRef)
conn = &fakeConnector{
getObjectObj: getObjIn,
getObjectQueryParams: NewQueryParams(false, nil),
getObjectRef: initRef,
getObjectError: nil,
resultObject: initObj,
updateObjectObj: updateObjIn,
updateObjectRef: initRef,
updateObjectError: fmt.Errorf("test error"),
fakeRefReturn: "",
}
objMgr = NewObjectManager(conn, cmpType, tenantID)
_, err = objMgr.UpdateAAAARecord(initRef, "", newRecordName, newIpAddr, "", newUseTtl, newTtl, newComment, newEas)
Expect(err).ToNot(BeNil())
})
})
})