@@ -27,7 +27,11 @@ import (
2727
2828var errBoom = errors .New ("boom" )
2929
30- const testLabelComponentName = "object.juggler.test.io/component"
30+ const (
31+ testLabelComponentKey = "object.juggler.test.io/component"
32+ testLabelManagedByKey = "object.juggler.test.io/managedBy"
33+ testLabelManagedByValue = "object.juggler.test.io/control-plane-operator"
34+ )
3135
3236func TestObjectReconciler_Install (t * testing.T ) {
3337 tests := []struct {
@@ -81,7 +85,7 @@ func TestObjectReconciler_Install(t *testing.T) {
8185 }
8286 if ! assert .Equal (t , secret .GetLabels (), map [string ]string {
8387 "app.kubernetes.io/managed-by" : "control-plane-operator" ,
84- testLabelComponentName : comp .GetName (),
88+ testLabelComponentKey : comp .GetName (),
8589 }) {
8690 return errors .New ("labels not equal" )
8791 }
@@ -121,7 +125,7 @@ func TestObjectReconciler_Install(t *testing.T) {
121125 }
122126 if ! assert .Equal (t , secret .GetLabels (), map [string ]string {
123127 "app.kubernetes.io/managed-by" : "control-plane-operator" ,
124- testLabelComponentName : comp .GetName (),
128+ testLabelComponentKey : comp .GetName (),
125129 }) {
126130 return errors .New ("labels not equal" )
127131 }
@@ -145,11 +149,10 @@ func TestObjectReconciler_Install(t *testing.T) {
145149 },
146150 name : "FakeObjectComponent" ,
147151 },
148- labelFunc : func (juggler.Component ) map [string ]string {
152+ labelFunc : func (comp juggler.Component ) map [string ]string {
149153 return map [string ]string {
150- testLabelComponentName : "custom-name" ,
151- "app.kubernetes.io/managed-by" : "managed-by-value" ,
152- "custom-label" : "custom-value" ,
154+ testLabelComponentKey : comp .GetName (),
155+ testLabelManagedByKey : testLabelManagedByValue ,
153156 }
154157 },
155158 validateFunc : func (ctx context.Context , c client.Client , comp juggler.Component ) error {
@@ -158,9 +161,8 @@ func TestObjectReconciler_Install(t *testing.T) {
158161 return err
159162 }
160163 if ! assert .Equal (t , secret .GetLabels (), map [string ]string {
161- testLabelComponentName : "custom-name" ,
162- "app.kubernetes.io/managed-by" : "managed-by-value" ,
163- "custom-label" : "custom-value" ,
164+ testLabelComponentKey : comp .GetName (),
165+ testLabelManagedByKey : testLabelManagedByValue ,
164166 }) {
165167 return errors .New ("labels not equal" )
166168 }
@@ -171,7 +173,7 @@ func TestObjectReconciler_Install(t *testing.T) {
171173 for _ , tt := range tests {
172174 t .Run (tt .name , func (t * testing.T ) {
173175 fakeRemoteClient := fake .NewClientBuilder ().WithObjects (tt .remoteObjects ... ).Build ()
174- r := NewReconciler (logr.Logger {}, fakeRemoteClient , testLabelComponentName ).
176+ r := NewReconciler (logr.Logger {}, fakeRemoteClient , testLabelComponentKey ).
175177 WithLabelFunc (tt .labelFunc )
176178 ctx := context .TODO ()
177179 actual := r .Install (ctx , tt .obj )
@@ -409,7 +411,7 @@ func TestObjectReconciler_Uninstall(t *testing.T) {
409411 for _ , tt := range tests {
410412 t .Run (tt .name , func (t * testing.T ) {
411413 fakeClient := fake .NewClientBuilder ().WithObjects (tt .remoteObjects ... ).Build ()
412- r := NewReconciler (logr.Logger {}, fakeClient , testLabelComponentName )
414+ r := NewReconciler (logr.Logger {}, fakeClient , testLabelComponentKey )
413415 ctx := context .TODO ()
414416 actual := r .Uninstall (ctx , tt .obj )
415417 if ! errors .Is (actual , tt .expected ) {
@@ -575,7 +577,7 @@ func TestObjectReconciler_Observe(t *testing.T) {
575577 }
576578 for _ , tt := range tests {
577579 t .Run (tt .name , func (t * testing.T ) {
578- r := NewReconciler (logr.Logger {}, fake .NewClientBuilder ().WithObjects (tt .remoteObjects ... ).Build (), testLabelComponentName )
580+ r := NewReconciler (logr.Logger {}, fake .NewClientBuilder ().WithObjects (tt .remoteObjects ... ).Build (), testLabelComponentKey )
579581 ctx := context .TODO ()
580582 actualObservation , actualError := r .Observe (ctx , tt .obj )
581583 if ! assert .Equal (t , tt .expectedObservation , actualObservation ) {
@@ -669,7 +671,7 @@ func Test_ObjectReconciler_DetectOrphanedComponents(t *testing.T) {
669671 for _ , tC := range testCases {
670672 t .Run (tC .desc , func (t * testing.T ) {
671673 fakeClient := fake .NewClientBuilder ().WithObjects (tC .initObjs ... ).WithInterceptorFuncs (tC .interceptorFuncs ).Build ()
672- r := NewReconciler (logr.Logger {}, fakeClient , testLabelComponentName )
674+ r := NewReconciler (logr.Logger {}, fakeClient , testLabelComponentKey )
673675 for _ , cc := range tC .configuredComponents {
674676 r .RegisterType (cc .(ObjectComponent ))
675677 }
0 commit comments