forked from infobloxopen/infoblox-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_manager_dtc_server_test.go
277 lines (248 loc) · 9.11 KB
/
object_manager_dtc_server_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
package ibclient
import (
"fmt"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Object Manager DTC Server", func() {
Describe("Create dtc server", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := "dtc_Server"
host := "2.3.4.5"
fakeRefReturn := fmt.Sprintf(
"dtc:server/ZG5zLmlkbnNfc2VydmVyJGR0Y19zZXJ2ZXIuY29t:%s",
name)
eas := EA{"Site": "blr"}
comment := "test client"
monitorRef := "dtc:monitor:snmp/ZG5zLmlkbnNfbW9uaXRvcl9odHRwJGh0dHA:snmp"
monitors := []map[string]interface{}{
{
"monitor": Monitor{Name: "snmp", Type: "snmp"},
"host": "2.3.4.5",
},
}
serverMonitor := []*DtcServerMonitor{
{
Monitor: monitorRef,
Host: "2.3.4.5",
},
}
sniHost := "sni_name"
useSniHost := true
objectAsResult := NewDtcServer(comment, name, host, false, false, eas, serverMonitor, sniHost, useSniHost)
objectAsResult.Ref = fakeRefReturn
aniFakeConnector := &fakeConnector{
createObjectObj: NewDtcServer(comment, name, host, false, false, eas, serverMonitor, sniHost, useSniHost),
getObjectRef: fakeRefReturn,
getObjectObj: map[string]interface{}{
"DtcMonitor": &DtcMonitorHttp{},
},
getObjectQueryParams: map[string]*QueryParams{
"DtcMonitor": NewQueryParams(false, map[string]string{"name": "snmp"}),
},
resultObject: map[string]interface{}{
"DtcMonitor": []DtcMonitorHttp{{
Ref: monitorRef,
}},
"DtcServer": objectAsResult,
},
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(aniFakeConnector, cmpType, tenantID)
var serverDtc *DtcServer
var err error
It("should pass expected DTC server Object to CreateObject", func() {
serverDtc, err = objMgr.CreateDtcServer(comment, name, host, false, false, eas, monitors, sniHost, useSniHost)
})
It("should return expected DTC server Object", func() {
Expect(err).To(BeNil())
Expect(serverDtc).To(Equal(aniFakeConnector.resultObject.(map[string]interface{})["DtcServer"]))
})
})
Describe("Update Dtc server", func() {
var (
err error
objMgr IBObjectManager
conn *fakeConnector
ref string
actualObj *DtcServer
)
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := "dtc_server_20"
It("Updating dtc_server_20, ttl, useTtl, comment and EA's", func() {
ref = fmt.Sprintf("dtc:server/ZG5zLmlkbnNfc2VydmVyJGR0Y19zZXJ2ZXIuY29t:%s", name)
initialEas := EA{"Site": "Blr"}
initialComment := "test client"
initialHost := "2.4.5.6"
initObj := NewDtcServer(initialComment, name, initialHost, false, false, initialEas, nil, "", false)
initObj.Ref = ref
expectedEas := EA{"Site": "Blr"}
updateName := "dtc_server_21"
updateComment := "new comment"
updateHost := "admin.com"
updatedRef := fmt.Sprintf("dtc:server/ZG5zLmlkbnNfc2VydmVyJGR0Y19zZXJ2ZXIuY29t:%s", name)
updateObjIn := NewDtcServer(updateComment, updateName, updateHost, true, false, expectedEas, nil, "sni_name", true)
updateObjIn.Ref = ref
expectedObj := NewDtcServer(updateComment, updateName, updateHost, true, false, expectedEas, nil, "sni_name", true)
expectedObj.Ref = updatedRef
conn = &fakeConnector{
getObjectObj: NewEmptyDtcServer(),
getObjectQueryParams: NewQueryParams(false, nil),
getObjectRef: updatedRef,
getObjectError: nil,
resultObject: expectedObj,
updateObjectObj: updateObjIn,
updateObjectRef: ref,
updateObjectError: nil,
fakeRefReturn: updatedRef,
}
objMgr = NewObjectManager(conn, cmpType, tenantID)
actualObj, err = objMgr.UpdateDtcServer(ref, updateComment, updateName, updateHost, true, false, expectedEas, nil, "sni_name", true)
Expect(err).To(BeNil())
Expect(*actualObj).To(BeEquivalentTo(*expectedObj))
})
})
Describe("Negative case: return an error message when sni_hostname is enabled and sni_name is not given ", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
comment := "test client"
name := "dtc_server"
host := "2.3.4.5"
eas := EA{"Site": "blr"}
conn := &fakeConnector{
createObjectObj: NewDtcServer(comment, name, host, true, false, eas, nil, "", true),
createObjectError: fmt.Errorf("if 'use_sni_hostname' is enabled then 'sni_hostname' must be provided or if 'sni_hostname' is provided then 'use_sni_hostname' must be enabled"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
var actualRecord, expectedObj *DtcServer
var err error
expectedObj = nil
It("should return expected dtc server object ", func() {
actualRecord, err = objMgr.CreateDtcServer(comment, name, host, true, false, eas, nil, "", true)
Expect(actualRecord).To(Equal(expectedObj))
Expect(err).To(Equal(conn.createObjectError))
})
})
Describe("Get server", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := "dtc_server"
comment := "get servers"
host := "2.3.4.5"
sniHost := "sni_hostname"
fakeRefReturn := fmt.Sprintf("dtc:server/ZG5zLmlkbnNfc2VydmVyJGR0Y19zZXJ2ZXIuY29t:%s", name)
queryParams := NewQueryParams(
false,
map[string]string{
"name": name,
"host": host,
})
conn := &fakeConnector{
createObjectObj: NewDtcServer(comment, name, host, false, false, nil, nil, sniHost, true),
getObjectRef: "",
getObjectObj: NewEmptyDtcServer(),
resultObject: []DtcServer{*NewDtcServer(comment, name, host, false, false, nil, nil, sniHost, true)},
fakeRefReturn: fakeRefReturn,
getObjectQueryParams: queryParams,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
conn.resultObject.([]DtcServer)[0].Ref = fakeRefReturn
var actualRecord *DtcServer
var err error
It("should pass expected Dtc Server Object to GetObject", func() {
actualRecord, err = objMgr.GetDtcServer(name, host)
Expect(err).To(BeNil())
Expect(*actualRecord).To(Equal(conn.resultObject.([]DtcServer)[0]))
})
})
Describe("Negative case : Error when name and host is not provided in Get function", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := ""
comment := "servers"
host := ""
sniHost := "sni_hostname"
fakeRefReturn := fmt.Sprintf("dtc:server/ZG5zLmlkbnNfc2VydmVyJGR0Y19zZXJ2ZXIuY29t:%s", name)
queryParams := NewQueryParams(
false,
map[string]string{
"name": name,
"host": host,
})
conn := &fakeConnector{
getObjectRef: "",
getObjectObj: NewEmptyDtcServer(),
resultObject: []DtcServer{*NewDtcServer(comment, name, host, false, false, nil, nil, sniHost, true)},
fakeRefReturn: fakeRefReturn,
getObjectQueryParams: queryParams,
getObjectError: fmt.Errorf("name and host of the server are required to retreive a unique dtc server"),
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
conn.resultObject.([]DtcServer)[0].Ref = fakeRefReturn
var actualRecord, expectedObj *DtcServer
var err error
expectedObj = nil
It("should return expected dtc server object", func() {
actualRecord, err = objMgr.GetDtcServer(name, host)
Expect(actualRecord).To(Equal(expectedObj))
Expect(err).To(Equal(conn.getObjectError))
})
})
Describe("Get All server", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := "dtc_server"
comment := "get servers"
host := "2.3.4.5"
sniHost := "sni_hostname"
fakeRefReturn := fmt.Sprintf("dtc:server/ZG5zLmlkbnNfc2VydmVyJGR0Y19zZXJ2ZXIuY29t:%s", name)
queryParams := NewQueryParams(
false,
map[string]string{
"name": name,
"host": host,
"comment": comment,
"sni_hostname": sniHost,
})
conn := &fakeConnector{
createObjectObj: NewDtcServer(comment, name, host, false, false, nil, nil, sniHost, true),
getObjectRef: "",
getObjectObj: NewEmptyDtcServer(),
resultObject: []DtcServer{*NewDtcServer(comment, name, host, false, false, nil, nil, sniHost, true)},
fakeRefReturn: fakeRefReturn,
getObjectQueryParams: queryParams,
}
objMgr := NewObjectManager(conn, cmpType, tenantID)
conn.resultObject.([]DtcServer)[0].Ref = fakeRefReturn
var actualRecord []DtcServer
var err error
It("should pass expected Dtc Server Object to GetObject", func() {
actualRecord, err = objMgr.GetAllDtcServer(queryParams)
Expect(err).To(BeNil())
Expect(actualRecord).To(Equal(conn.resultObject.([]DtcServer)))
})
})
Describe("Delete DTC server", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
name := "dtc_server_20"
deleteRef := fmt.Sprintf("dtc:server/ZG5zLmlkbnNfc2VydmVyJGR0Y19zZXJ2ZXIuY29t:%s", name)
fakeRefReturn := deleteRef
nwFakeConnector := &fakeConnector{
deleteObjectRef: deleteRef,
fakeRefReturn: fakeRefReturn,
}
objMgr := NewObjectManager(nwFakeConnector, cmpType, tenantID)
var actualRef string
var err error
It("should pass expected DTC server Ref to DeleteObject", func() {
actualRef, err = objMgr.DeleteDtcServer(deleteRef)
})
It("should return expected DTC server Ref", func() {
Expect(actualRef).To(Equal(fakeRefReturn))
Expect(err).To(BeNil())
})
})
})