@@ -32,6 +32,9 @@ import (
3232 "github.com/operator-framework/operator-sdk/internal/olm/operator"
3333)
3434
35+ const name = "fakeName"
36+ const namespace = "fakeNS"
37+
3538var _ = Describe ("OperatorInstaller" , func () {
3639 Describe ("NewOperatorInstaller" , func () {
3740 It ("should create an OperatorInstaller" , func () {
@@ -161,47 +164,47 @@ var _ = Describe("OperatorInstaller", func() {
161164 oi .cfg .Client = fake .NewClientBuilder ().WithScheme (sch ).WithObjects (
162165 & v1alpha1.InstallPlan {
163166 ObjectMeta : metav1.ObjectMeta {
164- Name : "fakeName" ,
165- Namespace : "fakeNS" ,
167+ Name : name ,
168+ Namespace : namespace ,
166169 },
167170 },
168171 ).Build ()
169172
170173 ip := & v1alpha1.InstallPlan {}
171174 ipKey := types.NamespacedName {
172- Namespace : "fakeNS" ,
173- Name : "fakeName" ,
175+ Namespace : namespace ,
176+ Name : name ,
174177 }
175178
176179 err := oi .cfg .Client .Get (context .TODO (), ipKey , ip )
177180 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 ))
180183
181184 // Test
182185 sub := & v1alpha1.Subscription {
183186 Status : v1alpha1.SubscriptionStatus {
184187 InstallPlanRef : & corev1.ObjectReference {
185- Name : "fakeName" ,
186- Namespace : "fakeNS" ,
188+ Name : name ,
189+ Namespace : namespace ,
187190 },
188191 },
189192 }
190193 err = oi .approveInstallPlan (context .TODO (), sub )
191194 Expect (err ).ToNot (HaveOccurred ())
192195 err = oi .cfg .Client .Get (context .TODO (), ipKey , ip )
193196 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 ))
196199 Expect (ip .Spec .Approved ).To (Equal (true ))
197200 })
198201 It ("should return an error if the install plan does not exist." , func () {
199202 oi .cfg .Client = fake .NewClientBuilder ().WithScheme (sch ).Build ()
200203 sub := & v1alpha1.Subscription {
201204 Status : v1alpha1.SubscriptionStatus {
202205 InstallPlanRef : & corev1.ObjectReference {
203- Name : "fakeName" ,
204- Namespace : "fakeNS" ,
206+ Name : name ,
207+ Namespace : namespace ,
205208 },
206209 },
207210 }
@@ -224,8 +227,8 @@ var _ = Describe("OperatorInstaller", func() {
224227 cfg .Client = fake .NewClientBuilder ().WithScheme (sch ).Build ()
225228
226229 oi = NewOperatorInstaller (cfg )
227- oi .StartingCSV = "fakeName"
228- oi .cfg .Namespace = "fakeNS"
230+ oi .StartingCSV = name
231+ oi .cfg .Namespace = namespace
229232 })
230233 It ("should return an error if the subscription does not exist." , func () {
231234 sub := newSubscription (oi .StartingCSV , oi .cfg .Namespace , withCatalogSource ("duplicate" , oi .cfg .Namespace ))
@@ -235,23 +238,66 @@ var _ = Describe("OperatorInstaller", func() {
235238 Expect (err .Error ()).Should (ContainSubstring ("install plan is not available for the subscription" ))
236239
237240 })
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+
239285 sub := & v1alpha1.Subscription {
240286 ObjectMeta : metav1.ObjectMeta {
241- Name : "fakeName" ,
242- Namespace : "fakeNS" ,
287+ Name : name ,
288+ Namespace : namespace ,
243289 },
244290 Status : v1alpha1.SubscriptionStatus {
245291 InstallPlanRef : & corev1.ObjectReference {
246- Name : "fakeName" ,
247- Namespace : "fakeNS" ,
292+ Name : name ,
293+ Namespace : namespace ,
248294 },
249295 },
250296 }
251297 err := oi .cfg .Client .Create (context .TODO (), sub )
252298 Expect (err ).ToNot (HaveOccurred ())
253299
254- err = oi .waitForInstallPlan (context .TODO (), sub )
300+ err = oi .waitForInstallPlan (context .TODO (), prevSub )
255301 Expect (err ).ToNot (HaveOccurred ())
256302 })
257303 })
@@ -550,7 +596,7 @@ var _ = Describe("OperatorInstaller", func() {
550596 Expect (err ).To (HaveOccurred ())
551597 })
552598 It ("should return nothing if namespace does not match" , func () {
553- oi .cfg .Namespace = "fakens"
599+ oi .cfg .Namespace = namespace
554600 _ = createOperatorGroupHelper (context .TODO (), client , "og1" , "atestns" )
555601 grp , found , err := oi .getOperatorGroup (context .TODO ())
556602 Expect (grp ).To (BeNil ())
0 commit comments