@@ -108,7 +108,7 @@ func Test_SimpleRevisionGenerator_Success(t *testing.T) {
108108 },
109109 }
110110
111- rev , err := b .GenerateRevision (fstest.MapFS {}, ext , map [string ]string {})
111+ rev , err := b .GenerateRevision (fstest.MapFS {}, ext , map [string ]string {}, map [ string ] string {} )
112112 require .NoError (t , err )
113113
114114 t .Log ("by checking the olm.operatorframework.io/owner label is set to the name of the ClusterExtension" )
@@ -188,11 +188,11 @@ func Test_SimpleRevisionGenerator_Renderer_Integration(t *testing.T) {
188188 BundleRenderer : r ,
189189 }
190190
191- _ , err := b .GenerateRevision (bundleFS , ext , map [string ]string {})
191+ _ , err := b .GenerateRevision (bundleFS , ext , map [string ]string {}, map [ string ] string {} )
192192 require .NoError (t , err )
193193}
194194
195- func Test_SimpleRevisionGenerator_AppliesObjectLabels (t * testing.T ) {
195+ func Test_SimpleRevisionGenerator_AppliesObjectLabelsAndRevisionAnnotations (t * testing.T ) {
196196 renderedObjs := []client.Object {
197197 & corev1.Service {
198198 ObjectMeta : metav1.ObjectMeta {
@@ -219,9 +219,13 @@ func Test_SimpleRevisionGenerator_AppliesObjectLabels(t *testing.T) {
219219 BundleRenderer : r ,
220220 }
221221
222+ revAnnotations := map [string ]string {
223+ "other" : "value" ,
224+ }
225+
222226 rev , err := b .GenerateRevision (fstest.MapFS {}, & ocv1.ClusterExtension {}, map [string ]string {
223227 "some" : "value" ,
224- })
228+ }, revAnnotations )
225229 require .NoError (t , err )
226230 t .Log ("by checking the rendered objects contain the given object labels" )
227231 for _ , phase := range rev .Spec .Phases {
@@ -232,6 +236,8 @@ func Test_SimpleRevisionGenerator_AppliesObjectLabels(t *testing.T) {
232236 }, revObj .Object .GetLabels ())
233237 }
234238 }
239+ t .Log ("by checking the generated revision contain the given annotations" )
240+ require .Equal (t , revAnnotations , rev .Annotations )
235241}
236242
237243func Test_SimpleRevisionGenerator_Failure (t * testing.T ) {
@@ -243,7 +249,7 @@ func Test_SimpleRevisionGenerator_Failure(t *testing.T) {
243249 BundleRenderer : r ,
244250 }
245251
246- rev , err := b .GenerateRevision (fstest.MapFS {}, & ocv1.ClusterExtension {}, map [string ]string {})
252+ rev , err := b .GenerateRevision (fstest.MapFS {}, & ocv1.ClusterExtension {}, map [string ]string {}, map [ string ] string {} )
247253 require .Nil (t , rev )
248254 t .Log ("by checking rendering errors are propagated" )
249255 require .Error (t , err )
@@ -298,20 +304,19 @@ func TestBoxcutter_Apply(t *testing.T) {
298304 }
299305
300306 testCases := []struct {
301- name string
302- mockBuilder applier.ClusterExtensionRevisionGenerator
303- existingObjs []client.Object
304- expectedErr string
305- validate func (t * testing.T , c client.Client )
306- expectedObjectsInPhase int
307+ name string
308+ mockBuilder applier.ClusterExtensionRevisionGenerator
309+ existingObjs []client.Object
310+ expectedErr string
311+ validate func (t * testing.T , c client.Client )
307312 }{
308313 {
309314 name : "first revision" ,
310315 mockBuilder : & mockBundleRevisionBuilder {
311- makeRevisionFunc : func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
316+ makeRevisionFunc : func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels , revisionAnnotations map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
312317 return & ocv1.ClusterExtensionRevision {
313318 ObjectMeta : metav1.ObjectMeta {
314- Annotations : map [ string ] string {} ,
319+ Annotations : revisionAnnotations ,
315320 Labels : map [string ]string {
316321 controllers .ClusterExtensionRevisionOwnerLabel : ext .Name ,
317322 },
@@ -353,15 +358,14 @@ func TestBoxcutter_Apply(t *testing.T) {
353358 assert .Equal (t , ext .Name , rev .OwnerReferences [0 ].Name )
354359 assert .Equal (t , ext .UID , rev .OwnerReferences [0 ].UID )
355360 },
356- expectedObjectsInPhase : 1 ,
357361 },
358362 {
359363 name : "no change, revision exists" ,
360364 mockBuilder : & mockBundleRevisionBuilder {
361- makeRevisionFunc : func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
365+ makeRevisionFunc : func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels , revisionAnnotations map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
362366 return & ocv1.ClusterExtensionRevision {
363367 ObjectMeta : metav1.ObjectMeta {
364- Annotations : map [ string ] string {} ,
368+ Annotations : revisionAnnotations ,
365369 Labels : map [string ]string {
366370 controllers .ClusterExtensionRevisionOwnerLabel : ext .Name ,
367371 },
@@ -400,15 +404,14 @@ func TestBoxcutter_Apply(t *testing.T) {
400404 require .Len (t , revList .Items , 1 )
401405 assert .Equal (t , "test-ext-1" , revList .Items [0 ].Name )
402406 },
403- expectedObjectsInPhase : 1 ,
404407 },
405408 {
406409 name : "new revision created when hash differs" ,
407410 mockBuilder : & mockBundleRevisionBuilder {
408- makeRevisionFunc : func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
411+ makeRevisionFunc : func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels , revisionAnnotations map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
409412 return & ocv1.ClusterExtensionRevision {
410413 ObjectMeta : metav1.ObjectMeta {
411- Annotations : map [ string ] string {} ,
414+ Annotations : revisionAnnotations ,
412415 Labels : map [string ]string {
413416 controllers .ClusterExtensionRevisionOwnerLabel : ext .Name ,
414417 },
@@ -462,12 +465,11 @@ func TestBoxcutter_Apply(t *testing.T) {
462465 assert .Equal (t , "test-ext-1" , newRev .Spec .Previous [0 ].Name )
463466 assert .Equal (t , types .UID ("rev-uid-1" ), newRev .Spec .Previous [0 ].UID )
464467 },
465- expectedObjectsInPhase : 1 ,
466468 },
467469 {
468470 name : "error from GenerateRevision" ,
469471 mockBuilder : & mockBundleRevisionBuilder {
470- makeRevisionFunc : func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
472+ makeRevisionFunc : func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels , revisionAnnotations map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
471473 return nil , errors .New ("render boom" )
472474 },
473475 },
@@ -497,15 +499,18 @@ func TestBoxcutter_Apply(t *testing.T) {
497499 testFS := fstest.MapFS {}
498500
499501 // Execute
500- objs , _ , err := boxcutter .Apply (t .Context (), testFS , ext , nil , nil )
502+ installSucceeded , installStatus , err := boxcutter .Apply (t .Context (), testFS , ext , nil , nil )
501503
502504 // Assert
503505 if tc .expectedErr != "" {
504506 require .Error (t , err )
505507 assert .Contains (t , err .Error (), tc .expectedErr )
508+ assert .False (t , installSucceeded )
509+ assert .Empty (t , installStatus )
506510 } else {
507511 require .NoError (t , err )
508- assert .Len (t , objs , tc .expectedObjectsInPhase )
512+ assert .False (t , installSucceeded )
513+ assert .Equal (t , installStatus , "New revision created" )
509514 }
510515
511516 if tc .validate != nil {
@@ -522,11 +527,11 @@ func TestBoxcutter_Apply(t *testing.T) {
522527
523528// mockBundleRevisionBuilder is a mock implementation of the ClusterExtensionRevisionGenerator for testing.
524529type mockBundleRevisionBuilder struct {
525- makeRevisionFunc func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels map [string ]string ) (* ocv1.ClusterExtensionRevision , error )
530+ makeRevisionFunc func (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels , revisionAnnotation map [string ]string ) (* ocv1.ClusterExtensionRevision , error )
526531}
527532
528- func (m * mockBundleRevisionBuilder ) GenerateRevision (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
529- return m .makeRevisionFunc (bundleFS , ext , objectLabels )
533+ func (m * mockBundleRevisionBuilder ) GenerateRevision (bundleFS fs.FS , ext * ocv1.ClusterExtension , objectLabels , revisionAnnotations map [string ]string ) (* ocv1.ClusterExtensionRevision , error ) {
534+ return m .makeRevisionFunc (bundleFS , ext , objectLabels , revisionAnnotations )
530535}
531536
532537type mockBundleRenderer func (bundleFS fs.FS , ext * ocv1.ClusterExtension ) ([]client.Object , error )
0 commit comments