@@ -32,6 +32,9 @@ import (
32
32
"github.com/operator-framework/operator-sdk/internal/olm/operator"
33
33
)
34
34
35
+ const name = "fakeName"
36
+ const namespace = "fakeNS"
37
+
35
38
var _ = Describe ("OperatorInstaller" , func () {
36
39
Describe ("NewOperatorInstaller" , func () {
37
40
It ("should create an OperatorInstaller" , func () {
@@ -161,47 +164,47 @@ var _ = Describe("OperatorInstaller", func() {
161
164
oi .cfg .Client = fake .NewClientBuilder ().WithScheme (sch ).WithObjects (
162
165
& v1alpha1.InstallPlan {
163
166
ObjectMeta : metav1.ObjectMeta {
164
- Name : "fakeName" ,
165
- Namespace : "fakeNS" ,
167
+ Name : name ,
168
+ Namespace : namespace ,
166
169
},
167
170
},
168
171
).Build ()
169
172
170
173
ip := & v1alpha1.InstallPlan {}
171
174
ipKey := types.NamespacedName {
172
- Namespace : "fakeNS" ,
173
- Name : "fakeName" ,
175
+ Namespace : namespace ,
176
+ Name : name ,
174
177
}
175
178
176
179
err := oi .cfg .Client .Get (context .TODO (), ipKey , ip )
177
180
Expect (err ).ToNot (HaveOccurred ())
178
- Expect (ip .Name ).To (Equal ("fakeName" ))
179
- Expect (ip .Namespace ).To (Equal ("fakeNS" ))
181
+ Expect (ip .Name ).To (Equal (name ))
182
+ Expect (ip .Namespace ).To (Equal (namespace ))
180
183
181
184
// Test
182
185
sub := & v1alpha1.Subscription {
183
186
Status : v1alpha1.SubscriptionStatus {
184
187
InstallPlanRef : & corev1.ObjectReference {
185
- Name : "fakeName" ,
186
- Namespace : "fakeNS" ,
188
+ Name : name ,
189
+ Namespace : namespace ,
187
190
},
188
191
},
189
192
}
190
193
err = oi .approveInstallPlan (context .TODO (), sub )
191
194
Expect (err ).ToNot (HaveOccurred ())
192
195
err = oi .cfg .Client .Get (context .TODO (), ipKey , ip )
193
196
Expect (err ).ToNot (HaveOccurred ())
194
- Expect (ip .Name ).To (Equal ("fakeName" ))
195
- Expect (ip .Namespace ).To (Equal ("fakeNS" ))
197
+ Expect (ip .Name ).To (Equal (name ))
198
+ Expect (ip .Namespace ).To (Equal (namespace ))
196
199
Expect (ip .Spec .Approved ).To (Equal (true ))
197
200
})
198
201
It ("should return an error if the install plan does not exist." , func () {
199
202
oi .cfg .Client = fake .NewClientBuilder ().WithScheme (sch ).Build ()
200
203
sub := & v1alpha1.Subscription {
201
204
Status : v1alpha1.SubscriptionStatus {
202
205
InstallPlanRef : & corev1.ObjectReference {
203
- Name : "fakeName" ,
204
- Namespace : "fakeNS" ,
206
+ Name : name ,
207
+ Namespace : namespace ,
205
208
},
206
209
},
207
210
}
@@ -224,8 +227,8 @@ var _ = Describe("OperatorInstaller", func() {
224
227
cfg .Client = fake .NewClientBuilder ().WithScheme (sch ).Build ()
225
228
226
229
oi = NewOperatorInstaller (cfg )
227
- oi .StartingCSV = "fakeName"
228
- oi .cfg .Namespace = "fakeNS"
230
+ oi .StartingCSV = name
231
+ oi .cfg .Namespace = namespace
229
232
})
230
233
It ("should return an error if the subscription does not exist." , func () {
231
234
sub := newSubscription (oi .StartingCSV , oi .cfg .Namespace , withCatalogSource ("duplicate" , oi .cfg .Namespace ))
@@ -235,23 +238,66 @@ var _ = Describe("OperatorInstaller", func() {
235
238
Expect (err .Error ()).Should (ContainSubstring ("install plan is not available for the subscription" ))
236
239
237
240
})
238
- It ("should return if subscription has an install plan." , func () {
241
+ It ("should return if subscription has an install plan and previous install plan is nil" , func () {
242
+ name := name
243
+ namespace := namespace
244
+ prevSub := & v1alpha1.Subscription {
245
+ ObjectMeta : metav1.ObjectMeta {
246
+ Name : name ,
247
+ Namespace : namespace ,
248
+ },
249
+ }
250
+
251
+ sub := & v1alpha1.Subscription {
252
+ ObjectMeta : metav1.ObjectMeta {
253
+ Name : name ,
254
+ Namespace : namespace ,
255
+ },
256
+ Status : v1alpha1.SubscriptionStatus {
257
+ InstallPlanRef : & corev1.ObjectReference {
258
+ Name : name ,
259
+ Namespace : namespace ,
260
+ },
261
+ },
262
+ }
263
+ err := oi .cfg .Client .Create (context .TODO (), sub )
264
+ Expect (err ).ToNot (HaveOccurred ())
265
+
266
+ err = oi .waitForInstallPlan (context .TODO (), prevSub )
267
+ Expect (err ).ToNot (HaveOccurred ())
268
+ })
269
+ It ("should return if subscription has an install plan and is different than previous install plan" , func () {
270
+ name := name
271
+ namespace := namespace
272
+ prevSub := & v1alpha1.Subscription {
273
+ ObjectMeta : metav1.ObjectMeta {
274
+ Name : name ,
275
+ Namespace : namespace ,
276
+ },
277
+ Status : v1alpha1.SubscriptionStatus {
278
+ InstallPlanRef : & corev1.ObjectReference {
279
+ Name : name + "diff" ,
280
+ Namespace : namespace + "diff" ,
281
+ },
282
+ },
283
+ }
284
+
239
285
sub := & v1alpha1.Subscription {
240
286
ObjectMeta : metav1.ObjectMeta {
241
- Name : "fakeName" ,
242
- Namespace : "fakeNS" ,
287
+ Name : name ,
288
+ Namespace : namespace ,
243
289
},
244
290
Status : v1alpha1.SubscriptionStatus {
245
291
InstallPlanRef : & corev1.ObjectReference {
246
- Name : "fakeName" ,
247
- Namespace : "fakeNS" ,
292
+ Name : name ,
293
+ Namespace : namespace ,
248
294
},
249
295
},
250
296
}
251
297
err := oi .cfg .Client .Create (context .TODO (), sub )
252
298
Expect (err ).ToNot (HaveOccurred ())
253
299
254
- err = oi .waitForInstallPlan (context .TODO (), sub )
300
+ err = oi .waitForInstallPlan (context .TODO (), prevSub )
255
301
Expect (err ).ToNot (HaveOccurred ())
256
302
})
257
303
})
@@ -550,7 +596,7 @@ var _ = Describe("OperatorInstaller", func() {
550
596
Expect (err ).To (HaveOccurred ())
551
597
})
552
598
It ("should return nothing if namespace does not match" , func () {
553
- oi .cfg .Namespace = "fakens"
599
+ oi .cfg .Namespace = namespace
554
600
_ = createOperatorGroupHelper (context .TODO (), client , "og1" , "atestns" )
555
601
grp , found , err := oi .getOperatorGroup (context .TODO ())
556
602
Expect (grp ).To (BeNil ())
0 commit comments