@@ -24,7 +24,6 @@ import (
24
24
"time"
25
25
26
26
"github.com/ibm/composable/pkg/apis"
27
- "github.com/ibm/composable/pkg/context"
28
27
"github.com/ibm/composable/test"
29
28
. "github.com/onsi/ginkgo"
30
29
. "github.com/onsi/gomega"
@@ -35,19 +34,14 @@ import (
35
34
"k8s.io/client-go/kubernetes/scheme"
36
35
"k8s.io/client-go/rest"
37
36
"k8s.io/klog"
38
- "sigs.k8s.io/controller-runtime/pkg/client"
39
37
"sigs.k8s.io/controller-runtime/pkg/envtest"
40
38
"sigs.k8s.io/controller-runtime/pkg/manager"
41
- "sigs.k8s.io/controller-runtime/pkg/reconcile"
42
39
)
43
40
44
41
var (
45
- c client.Client
46
- cfg * rest.Config
47
- testNs string
48
- scontext context.Context
49
- t * envtest.Environment
50
- stop chan struct {}
42
+ testContext test.TestContext
43
+ testEnv * envtest.Environment
44
+ stop chan struct {}
51
45
)
52
46
53
47
func TestComposable (t * testing.T ) {
@@ -63,35 +57,36 @@ func TestComposable(t *testing.T) {
63
57
64
58
var _ = BeforeSuite (func () {
65
59
66
- t = & envtest.Environment {
60
+ testEnv = & envtest.Environment {
67
61
CRDDirectoryPaths : []string {filepath .Join (".." , ".." , ".." , "config" , "crds" ),
68
62
filepath .Join ("./testdata" , "crds" )},
69
63
ControlPlaneStartTimeout : 2 * time .Minute ,
70
64
}
71
65
apis .AddToScheme (scheme .Scheme )
72
66
73
67
var err error
74
- if cfg , err = t .Start (); err != nil {
68
+ var cfg * rest.Config
69
+ if cfg , err = testEnv .Start (); err != nil {
75
70
log .Fatal (err )
76
71
}
77
72
78
73
syncPeriod := 30 * time .Second // set a sync period
79
74
mgr , err := manager .New (cfg , manager.Options {SyncPeriod : & syncPeriod })
80
75
Expect (err ).NotTo (HaveOccurred ())
81
76
82
- c = mgr .GetClient ()
77
+ client : = mgr .GetClient ()
83
78
84
79
recFn := newReconciler (mgr )
85
80
Expect (add (mgr , recFn )).NotTo (HaveOccurred ())
86
81
stop = test .StartTestManager (mgr )
87
- testNs = test .SetupKubeOrDie (cfg , "test-ns-" )
88
- scontext = context . New ( c , reconcile. Request { NamespacedName : types. NamespacedName { Name : "" , Namespace : testNs }} )
82
+ testNs : = test .SetupKubeOrDie (cfg , "test-ns-" )
83
+ testContext = test . NewTestContext ( client , testNs )
89
84
90
85
})
91
86
92
87
var _ = AfterSuite (func () {
93
88
close (stop )
94
- t .Stop ()
89
+ testEnv .Stop ()
95
90
})
96
91
97
92
var _ = Describe ("test Composable operations" , func () {
@@ -107,28 +102,27 @@ var _ = Describe("test Composable operations", func() {
107
102
AfterEach (func () {
108
103
// delete the Composable object
109
104
comp := test .LoadCompasable (dataDir + "compCopy.yaml" )
110
- test .DeleteInNs (scontext , & comp , false )
111
- Eventually (test .GetObject (scontext , & comp )).Should (BeNil ())
105
+ test .DeleteInNs (testContext , & comp , false )
106
+ Eventually (test .GetObject (testContext , & comp )).Should (BeNil ())
112
107
113
108
obj := test .LoadObject (dataDir + "inputDataObject.yaml" , & unstructured.Unstructured {})
114
- test .DeleteObject (scontext , obj , false )
115
- Eventually (test .GetObject (scontext , obj )).Should (BeNil ())
109
+ test .DeleteObject (testContext , obj , false )
110
+ Eventually (test .GetObject (testContext , obj )).Should (BeNil ())
116
111
})
117
112
118
113
It ("Composable should successfully set default values to the output object" , func () {
119
114
120
-
121
115
By ("Deploy Composable object" )
122
116
comp := test .LoadCompasable (dataDir + "compCopy.yaml" )
123
- test .PostInNs (scontext , & comp , true , 0 )
124
- Eventually (test .GetObject (scontext , & comp )).ShouldNot (BeNil ())
117
+ test .PostInNs (testContext , & comp , true , 0 )
118
+ Eventually (test .GetObject (testContext , & comp )).ShouldNot (BeNil ())
125
119
126
120
By ("Get Output object" )
127
121
groupVersionKind := schema.GroupVersionKind {Kind : "OutputValue" , Version : "v1" , Group : "test.ibmcloud.ibm.com" }
128
122
unstrObj .SetGroupVersionKind (groupVersionKind )
129
- objNamespacedname := types.NamespacedName {Namespace : testNs , Name : "comp-out" }
123
+ objNamespacedname := types.NamespacedName {Namespace : testContext . Namespace () , Name : "comp-out" }
130
124
klog .V (5 ).Infof ("Get Object %s\n " , objNamespacedname )
131
- Eventually (test .GetUnstructuredObject (scontext , objNamespacedname , & unstrObj )).Should (Succeed ())
125
+ Eventually (test .GetUnstructuredObject (testContext , objNamespacedname , & unstrObj )).Should (Succeed ())
132
126
testSpec , ok := unstrObj .Object [spec ].(map [string ]interface {})
133
127
Ω (ok ).Should (BeTrue ())
134
128
@@ -148,13 +142,13 @@ var _ = Describe("test Composable operations", func() {
148
142
Ω (testSpec ["stringFromBase64" ]).Should (Equal ("default" ))
149
143
150
144
By ("default arrayStrings" )
151
- Ω (testSpec ["arrayStrings" ]).Should (BeEquivalentTo ([]interface {}{"aa" ,"bb" ,"cc" }))
145
+ Ω (testSpec ["arrayStrings" ]).Should (BeEquivalentTo ([]interface {}{"aa" , "bb" , "cc" }))
152
146
153
147
By ("default arrayIntegers" )
154
- Ω (testSpec ["arrayIntegers" ]).Should (BeEquivalentTo ([]interface {}{int64 (1 ),int64 (0 ),int64 (1 )}))
148
+ Ω (testSpec ["arrayIntegers" ]).Should (BeEquivalentTo ([]interface {}{int64 (1 ), int64 (0 ), int64 (1 )}))
155
149
156
150
By ("default objectValue" )
157
- Ω (testSpec ["objectValue" ]).Should (BeEquivalentTo (map [string ]interface {}{"family" : "DefaultFamilyName" , "first" : "DefaultFirstName" , "age" : int64 (- 1 )}))
151
+ Ω (testSpec ["objectValue" ]).Should (BeEquivalentTo (map [string ]interface {}{"family" : "DefaultFamilyName" , "first" : "DefaultFirstName" , "age" : int64 (- 1 )}))
158
152
159
153
By ("default stringJson2Value" )
160
154
Ω (testSpec ["stringJson2Value" ]).Should (BeEquivalentTo ("default1,default2,default3" ))
@@ -165,25 +159,25 @@ var _ = Describe("test Composable operations", func() {
165
159
166
160
By ("Deploy input Object" )
167
161
obj := test .LoadObject (dataDir + "inputDataObject.yaml" , & unstructured.Unstructured {})
168
- test .CreateObject (scontext , obj , true , 0 )
162
+ test .CreateObject (testContext , obj , true , 0 )
169
163
170
164
groupVersionKind := schema.GroupVersionKind {Kind : "InputValue" , Version : "v1" , Group : "test.ibmcloud.ibm.com" }
171
165
unstrObj .SetGroupVersionKind (groupVersionKind )
172
166
objNamespacedname := types.NamespacedName {Namespace : "default" , Name : "inputdata" }
173
167
klog .V (5 ).Infof ("Get Object %s\n " , objNamespacedname )
174
- Eventually (test .GetUnstructuredObject (scontext , objNamespacedname , & unstrObj )).Should (Succeed ())
168
+ Eventually (test .GetUnstructuredObject (testContext , objNamespacedname , & unstrObj )).Should (Succeed ())
175
169
176
170
By ("Deploy Composable object" )
177
171
comp := test .LoadCompasable (dataDir + "compCopy.yaml" )
178
- test .PostInNs (scontext , & comp , true , 0 )
179
- Eventually (test .GetObject (scontext , & comp )).ShouldNot (BeNil ())
172
+ test .PostInNs (testContext , & comp , true , 0 )
173
+ Eventually (test .GetObject (testContext , & comp )).ShouldNot (BeNil ())
180
174
181
175
By ("Get Output object" )
182
176
groupVersionKind = schema.GroupVersionKind {Kind : "OutputValue" , Version : "v1" , Group : "test.ibmcloud.ibm.com" }
183
177
unstrObj .SetGroupVersionKind (groupVersionKind )
184
- objNamespacedname = types.NamespacedName {Namespace : testNs , Name : "comp-out" }
178
+ objNamespacedname = types.NamespacedName {Namespace : testContext . Namespace () , Name : "comp-out" }
185
179
klog .V (5 ).Infof ("Get Object %s\n " , objNamespacedname )
186
- Eventually (test .GetUnstructuredObject (scontext , objNamespacedname , & unstrObj )).Should (Succeed ())
180
+ Eventually (test .GetUnstructuredObject (testContext , objNamespacedname , & unstrObj )).Should (Succeed ())
187
181
testSpec , ok := unstrObj .Object [spec ].(map [string ]interface {})
188
182
Ω (ok ).Should (BeTrue ())
189
183
@@ -208,10 +202,10 @@ var _ = Describe("test Composable operations", func() {
208
202
Ω (testSpec ["arrayStrings" ]).Should (Equal (strArray ))
209
203
210
204
By ("copy arrayIntegers" )
211
- Ω (testSpec ["arrayIntegers" ]).Should (Equal ([]interface {}{int64 (1 ),int64 (2 ),int64 (3 ),int64 (4 )}))
205
+ Ω (testSpec ["arrayIntegers" ]).Should (Equal ([]interface {}{int64 (1 ), int64 (2 ), int64 (3 ), int64 (4 )}))
212
206
213
207
By ("copy objectValue" )
214
- Ω (testSpec ["objectValue" ]).Should (Equal (map [string ]interface {}{"family" : "FamilyName" , "first" : "FirstName" , "age" : int64 (27 )}))
208
+ Ω (testSpec ["objectValue" ]).Should (Equal (map [string ]interface {}{"family" : "FamilyName" , "first" : "FirstName" , "age" : int64 (27 )}))
215
209
216
210
By ("copy stringJson2Value" )
217
211
val , _ := Array2CSStringTransformer (strArray )
@@ -223,32 +217,32 @@ var _ = Describe("test Composable operations", func() {
223
217
224
218
gvkIn := schema.GroupVersionKind {Kind : "InputValue" , Version : "v1" , Group : "test.ibmcloud.ibm.com" }
225
219
gvkOut := schema.GroupVersionKind {Kind : "OutputValue" , Version : "v1" , Group : "test.ibmcloud.ibm.com" }
226
- objNamespacednameIn := types.NamespacedName {Namespace : "default" , Name : "inputdata" }
227
- objNamespacednameOut := types.NamespacedName {Namespace : testNs , Name : "comp-out" }
220
+ objNamespacednameIn := types.NamespacedName {Namespace : "default" , Name : "inputdata" }
221
+ objNamespacednameOut := types.NamespacedName {Namespace : testContext . Namespace () , Name : "comp-out" }
228
222
229
223
//unstrObj.SetGroupVersionKind(gvkOut)
230
224
// First, the output object is created with defult values, after that we deploy the inputObject and will check
231
225
// that all Output object filed are updated.
232
226
By ("check that input object doesn't exist" ) // the object should not exist
233
227
unstrObj .SetGroupVersionKind (gvkIn )
234
- Ω (test .GetUnstructuredObject (scontext , objNamespacednameIn , & unstrObj )()).Should (HaveOccurred ())
228
+ Ω (test .GetUnstructuredObject (testContext , objNamespacednameIn , & unstrObj )()).Should (HaveOccurred ())
235
229
236
230
By ("check taht output object doesn't exist. If it does => remove it " ) // the object should not exist, or we delete it
237
231
unstrObj .SetGroupVersionKind (gvkOut )
238
- err2 := test .GetUnstructuredObject (scontext , objNamespacednameOut , & unstrObj )()
232
+ err2 := test .GetUnstructuredObject (testContext , objNamespacednameOut , & unstrObj )()
239
233
if err2 == nil {
240
- test .DeleteObject (scontext , & unstrObj , false )
241
- Eventually (test .GetObject (scontext , & unstrObj )).Should (BeNil ())
234
+ test .DeleteObject (testContext , & unstrObj , false )
235
+ Eventually (test .GetObject (testContext , & unstrObj )).Should (BeNil ())
242
236
}
243
237
244
238
By ("deploy Composable object" )
245
239
comp := test .LoadCompasable (dataDir + "compCopy.yaml" )
246
- test .PostInNs (scontext , & comp , true , 0 )
247
- Eventually (test .GetObject (scontext , & comp )).ShouldNot (BeNil ())
240
+ test .PostInNs (testContext , & comp , true , 0 )
241
+ Eventually (test .GetObject (testContext , & comp )).ShouldNot (BeNil ())
248
242
249
243
By ("get Output object" )
250
244
unstrObj .SetGroupVersionKind (gvkOut )
251
- Eventually (test .GetUnstructuredObject (scontext , objNamespacednameOut , & unstrObj )).Should (Succeed ())
245
+ Eventually (test .GetUnstructuredObject (testContext , objNamespacednameOut , & unstrObj )).Should (Succeed ())
252
246
testSpec , ok := unstrObj .Object [spec ].(map [string ]interface {})
253
247
Ω (ok ).Should (BeTrue ())
254
248
@@ -261,16 +255,16 @@ var _ = Describe("test Composable operations", func() {
261
255
262
256
By ("deploy input Object" )
263
257
obj := test .LoadObject (dataDir + "inputDataObject.yaml" , & unstructured.Unstructured {})
264
- test .CreateObject (scontext , obj , true , 0 )
258
+ test .CreateObject (testContext , obj , true , 0 )
265
259
266
260
unstrObj .SetGroupVersionKind (gvkIn )
267
- Eventually (test .GetUnstructuredObject (scontext , objNamespacednameIn , & unstrObj )).Should (Succeed ())
261
+ Eventually (test .GetUnstructuredObject (testContext , objNamespacednameIn , & unstrObj )).Should (Succeed ())
268
262
269
263
By ("check updated inValue" )
270
264
unstrObj = unstructured.Unstructured {}
271
265
unstrObj .SetGroupVersionKind (gvkOut )
272
- Eventually ( func () (int64 , error ) {
273
- err := test .GetUnstructuredObject (scontext , objNamespacednameOut , & unstrObj )()
266
+ Eventually (func () (int64 , error ) {
267
+ err := test .GetUnstructuredObject (testContext , objNamespacednameOut , & unstrObj )()
274
268
if err != nil {
275
269
return int64 (0 ), err
276
270
}
@@ -295,10 +289,10 @@ var _ = Describe("test Composable operations", func() {
295
289
Ω (testSpec ["arrayStrings" ]).Should (Equal (strArray ))
296
290
297
291
By ("check updated arrayIntegers" )
298
- Ω (testSpec ["arrayIntegers" ]).Should (Equal ([]interface {}{int64 (1 ),int64 (2 ),int64 (3 ),int64 (4 )}))
292
+ Ω (testSpec ["arrayIntegers" ]).Should (Equal ([]interface {}{int64 (1 ), int64 (2 ), int64 (3 ), int64 (4 )}))
299
293
300
294
By ("check updated objectValue" )
301
- Ω (testSpec ["objectValue" ]).Should (Equal (map [string ]interface {}{"family" : "FamilyName" , "first" : "FirstName" , "age" : int64 (27 )}))
295
+ Ω (testSpec ["objectValue" ]).Should (Equal (map [string ]interface {}{"family" : "FamilyName" , "first" : "FirstName" , "age" : int64 (27 )}))
302
296
303
297
By ("check updated stringJson2Value" )
304
298
val , _ := Array2CSStringTransformer (strArray )
@@ -315,22 +309,22 @@ var _ = Describe("IBM cloud-operators compatibility", func() {
315
309
It ("should correctly create the Service instance" , func () {
316
310
317
311
comp := test .LoadCompasable (dataDir + "comp.yaml" )
318
- test .PostInNs (scontext , & comp , true , 0 )
319
- Eventually (test .GetObject (scontext , & comp )).ShouldNot (BeNil ())
312
+ test .PostInNs (testContext , & comp , true , 0 )
313
+ Eventually (test .GetObject (testContext , & comp )).ShouldNot (BeNil ())
320
314
321
- objNamespacedname := types.NamespacedName {Namespace : scontext .Namespace (), Name : "mymessagehub" }
315
+ objNamespacedname := types.NamespacedName {Namespace : testContext .Namespace (), Name : "mymessagehub" }
322
316
unstrObj := unstructured.Unstructured {}
323
317
unstrObj .SetGroupVersionKind (groupVersionKind )
324
318
klog .V (5 ).Infof ("Get Object %s\n " , objNamespacedname )
325
- Eventually (test .GetUnstructuredObject (scontext , objNamespacedname , & unstrObj )).Should (Succeed ())
326
- Eventually (test .GetState (scontext , & comp )).Should (Equal (OnlineStatus ))
319
+ Eventually (test .GetUnstructuredObject (testContext , objNamespacedname , & unstrObj )).Should (Succeed ())
320
+ Eventually (test .GetState (testContext , & comp )).Should (Equal (OnlineStatus ))
327
321
328
322
})
329
323
330
324
It ("should delete the Composable and Service instances" , func () {
331
325
comp := test .LoadCompasable (dataDir + "comp.yaml" )
332
- test .DeleteInNs (scontext , & comp , false )
333
- Eventually (test .GetObject (scontext , & comp )).Should (BeNil ())
326
+ test .DeleteInNs (testContext , & comp , false )
327
+ Eventually (test .GetObject (testContext , & comp )).Should (BeNil ())
334
328
})
335
329
336
330
})
@@ -340,48 +334,48 @@ var _ = Describe("IBM cloud-operators compatibility", func() {
340
334
341
335
BeforeEach (func () {
342
336
obj := test .LoadObject (dataDir + "mysecret.yaml" , & v1.Secret {})
343
- test .PostInNs (scontext , obj , true , 0 )
344
- objNamespacedname = types.NamespacedName {Namespace : scontext .Namespace (), Name : "mymessagehub" }
337
+ test .PostInNs (testContext , obj , true , 0 )
338
+ objNamespacedname = types.NamespacedName {Namespace : testContext .Namespace (), Name : "mymessagehub" }
345
339
})
346
340
347
341
AfterEach (func () {
348
342
obj := test .LoadObject (dataDir + "mysecret.yaml" , & v1.Secret {})
349
- test .DeleteInNs (scontext , obj , false )
343
+ test .DeleteInNs (testContext , obj , false )
350
344
})
351
345
352
346
It ("should correctly create the Service instance according to parameters from a Secret object" , func () {
353
347
comp := test .LoadCompasable (dataDir + "comp1.yaml" )
354
- test .PostInNs (scontext , & comp , false , 0 )
355
- Eventually (test .GetObject (scontext , & comp )).ShouldNot (BeNil ())
348
+ test .PostInNs (testContext , & comp , false , 0 )
349
+ Eventually (test .GetObject (testContext , & comp )).ShouldNot (BeNil ())
356
350
357
351
unstrObj := unstructured.Unstructured {}
358
352
unstrObj .SetGroupVersionKind (groupVersionKind )
359
353
klog .V (5 ).Infof ("Get Object %s\n " , objNamespacedname )
360
- Eventually (test .GetUnstructuredObject (scontext , objNamespacedname , & unstrObj )).Should (Succeed ())
354
+ Eventually (test .GetUnstructuredObject (testContext , objNamespacedname , & unstrObj )).Should (Succeed ())
361
355
Ω (getPlan (unstrObj .Object )).Should (Equal ("standard" ))
362
- Eventually (test .GetObject (scontext , & comp )).ShouldNot (BeNil ())
363
- Eventually (test .GetState (scontext , & comp )).Should (Equal (OnlineStatus ))
364
- test .DeleteInNs (scontext , & comp , false )
365
- Eventually (test .GetObject (scontext , & comp )).Should (BeNil ())
356
+ Eventually (test .GetObject (testContext , & comp )).ShouldNot (BeNil ())
357
+ Eventually (test .GetState (testContext , & comp )).Should (Equal (OnlineStatus ))
358
+ test .DeleteInNs (testContext , & comp , false )
359
+ Eventually (test .GetObject (testContext , & comp )).Should (BeNil ())
366
360
})
367
361
368
362
It ("should correctly create the Service instance according to parameters from a ConfigMap" , func () {
369
363
obj := test .LoadObject (dataDir + "myconfigmap.yaml" , & v1.ConfigMap {})
370
- test .PostInNs (scontext , obj , true , 0 )
364
+ test .PostInNs (testContext , obj , true , 0 )
371
365
372
366
comp := test .LoadCompasable (dataDir + "comp2.yaml" )
373
- test .PostInNs (scontext , & comp , false , 0 )
374
- Eventually (test .GetObject (scontext , & comp )).ShouldNot (BeNil ())
367
+ test .PostInNs (testContext , & comp , false , 0 )
368
+ Eventually (test .GetObject (testContext , & comp )).ShouldNot (BeNil ())
375
369
376
370
unstrObj := unstructured.Unstructured {}
377
371
unstrObj .SetGroupVersionKind (groupVersionKind )
378
372
klog .V (5 ).Infof ("Get Object %s\n " , objNamespacedname )
379
- Eventually (test .GetUnstructuredObject (scontext , objNamespacedname , & unstrObj )).Should (Succeed ())
373
+ Eventually (test .GetUnstructuredObject (testContext , objNamespacedname , & unstrObj )).Should (Succeed ())
380
374
Ω (getPlan (unstrObj .Object )).Should (Equal ("standard" ))
381
- Eventually (test .GetObject (scontext , & comp )).ShouldNot (BeNil ())
382
- Eventually (test .GetState (scontext , & comp )).Should (Equal (OnlineStatus ))
383
- test .DeleteInNs (scontext , & comp , false )
384
- Eventually (test .GetObject (scontext , & comp )).Should (BeNil ())
375
+ Eventually (test .GetObject (testContext , & comp )).ShouldNot (BeNil ())
376
+ Eventually (test .GetState (testContext , & comp )).Should (Equal (OnlineStatus ))
377
+ test .DeleteInNs (testContext , & comp , false )
378
+ Eventually (test .GetObject (testContext , & comp )).Should (BeNil ())
385
379
})
386
380
})
387
381
0 commit comments