Skip to content

Commit de68465

Browse files
committed
adapt to testing library changes
Signed-off-by: Johannes Aubart <johannes.aubart@sap.com>
1 parent 7237820 commit de68465

3 files changed

Lines changed: 26 additions & 11 deletions

File tree

internal/controller/core/authentication/controller_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,18 @@ const (
8484

8585
func testEnvWithAPIServerAccess(testDataPathSegments ...string) *testing.ComplexEnvironment {
8686
env := testutils.DefaultTestSetupBuilder(testDataPathSegments...).WithFakeClient(testutils.APIServerCluster, testutils.Scheme).WithReconcilerConstructor(authReconciler, getReconciler, testutils.CrateCluster).Build()
87-
env.Reconcilers[authReconciler].(*authentication.AuthenticationReconciler).SetAPIServerAccess(&testutils.TestAPIServerAccess{Client: env.Client(testutils.APIServerCluster)})
87+
controller, err := testing.ReconcilerAs[*authentication.AuthenticationReconciler](env.Reconciler(authReconciler))
88+
Expect(err).ToNot(HaveOccurred())
89+
controller.SetAPIServerAccess(&testutils.TestAPIServerAccess{Client: env.Client(testutils.APIServerCluster)})
90+
8891
return env
8992
}
9093

9194
func testEnvWithAPIServerAccessWithCrateIdentityProvider(testDataPathSegments ...string) *testing.ComplexEnvironment {
9295
env := testutils.DefaultTestSetupBuilder(testDataPathSegments...).WithFakeClient(testutils.APIServerCluster, testutils.Scheme).WithReconcilerConstructor(authReconciler, getReconcilerWithCrateIdentityProvider, testutils.CrateCluster).Build()
93-
env.Reconcilers[authReconciler].(*authentication.AuthenticationReconciler).SetAPIServerAccess(&testutils.TestAPIServerAccess{Client: env.Client(testutils.APIServerCluster)})
96+
controller, err := testing.ReconcilerAs[*authentication.AuthenticationReconciler](env.Reconciler(authReconciler))
97+
Expect(err).ToNot(HaveOccurred())
98+
controller.SetAPIServerAccess(&testutils.TestAPIServerAccess{Client: env.Client(testutils.APIServerCluster)})
9499
return env
95100
}
96101

@@ -446,7 +451,9 @@ var _ = Describe("CO-1153 Authentication Controller", func() {
446451

447452
env := testEnvWithAPIServerAccess("testdata", "test-08")
448453
apiServerAccess := &testutils.TestAPIServerAccess{Client: env.Client(testutils.APIServerCluster)}
449-
env.Reconcilers[authReconciler].(*authentication.AuthenticationReconciler).SetAPIServerAccess(apiServerAccess)
454+
controller, err := testing.ReconcilerAs[*authentication.AuthenticationReconciler](env.Reconciler(authReconciler))
455+
Expect(err).ToNot(HaveOccurred())
456+
controller.SetAPIServerAccess(apiServerAccess)
450457

451458
auth := &openmcpv1alpha1.Authentication{}
452459
err = env.Client(testutils.CrateCluster).Get(env.Ctx, types.NamespacedName{Name: "test", Namespace: "test"}, auth)

internal/controller/core/authorization/clusteradmin/controller_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ func testEnvWithAPIServerAccess(testDataPathSegments ...string) *testing.Complex
4141
WithReconcilerConstructor(clusterAdminReconciler, getReconciler, testutils.CrateCluster).
4242
WithDynamicObjectsWithStatus(testutils.CrateCluster).
4343
Build()
44-
env.Reconcilers[clusterAdminReconciler].(*clusteradmin.ClusterAdminReconciler).
45-
SetAPIServerAccess(&testutils.TestAPIServerAccess{Client: env.Client(testutils.APIServerCluster)})
44+
controller, err := testing.ReconcilerAs[*clusteradmin.ClusterAdminReconciler](env.Reconciler(clusterAdminReconciler))
45+
Expect(err).ToNot(HaveOccurred())
46+
controller.SetAPIServerAccess(&testutils.TestAPIServerAccess{Client: env.Client(testutils.APIServerCluster)})
4647

4748
return env
4849
}

internal/controller/core/authorization/controller_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ func getReconciler(c ...client.Client) reconcile.Reconciler {
149149

150150
func testEnvWithAPIServerAccess(testDataPathSegments ...string) *testing.ComplexEnvironment {
151151
env := testutils.DefaultTestSetupBuilder(testDataPathSegments...).WithFakeClient(testutils.APIServerCluster, testutils.Scheme).WithReconcilerConstructor(authzReconciler, getReconciler, testutils.CrateCluster).Build()
152-
env.Reconcilers[authzReconciler].(*authorization.AuthorizationReconciler).SetAPIServerAccess(&testutils.TestAPIServerAccess{Client: env.Client(testutils.APIServerCluster)})
152+
controller, err := testing.ReconcilerAs[*authorization.AuthorizationReconciler](env.Reconciler(authzReconciler))
153+
Expect(err).ToNot(HaveOccurred())
154+
controller.SetAPIServerAccess(&testutils.TestAPIServerAccess{Client: env.Client(testutils.APIServerCluster)})
153155
return env
154156
}
155157

@@ -507,7 +509,8 @@ var _ = Describe("CO-1153 Authorization Controller", func() {
507509
_ = env.ShouldReconcile(authzReconciler, req)
508510

509511
testWorker := testutils.NewTestWorker(env.Client(testutils.CrateCluster), env.Client(testutils.APIServerCluster))
510-
controller := env.Reconciler(authzReconciler).(*authorization.AuthorizationReconciler)
512+
controller, err := testing.ReconcilerAs[*authorization.AuthorizationReconciler](env.Reconciler(authzReconciler))
513+
Expect(err).ToNot(HaveOccurred())
511514
controller.RegisterTasks(testWorker)
512515

513516
as := &openmcpv1alpha1.APIServer{}
@@ -603,7 +606,8 @@ var _ = Describe("CO-1153 Authorization Controller", func() {
603606
_ = env.ShouldReconcile(authzReconciler, req)
604607

605608
testWorker := testutils.NewTestWorker(env.Client(testutils.CrateCluster), env.Client(testutils.APIServerCluster))
606-
controller := env.Reconciler(authzReconciler).(*authorization.AuthorizationReconciler)
609+
controller, err := testing.ReconcilerAs[*authorization.AuthorizationReconciler](env.Reconciler(authzReconciler))
610+
Expect(err).ToNot(HaveOccurred())
607611
controller.RegisterTasks(testWorker)
608612

609613
as := &openmcpv1alpha1.APIServer{}
@@ -667,7 +671,8 @@ var _ = Describe("CO-1153 Authorization Controller", func() {
667671
_ = env.ShouldReconcile(authzReconciler, req)
668672

669673
testWorker := testutils.NewTestWorker(env.Client(testutils.CrateCluster), env.Client(testutils.APIServerCluster))
670-
controller := env.Reconciler(authzReconciler).(*authorization.AuthorizationReconciler)
674+
controller, err := testing.ReconcilerAs[*authorization.AuthorizationReconciler](env.Reconciler(authzReconciler))
675+
Expect(err).ToNot(HaveOccurred())
671676
controller.RegisterTasks(testWorker)
672677

673678
as := &openmcpv1alpha1.APIServer{}
@@ -762,7 +767,8 @@ var _ = Describe("CO-1153 Authorization Controller", func() {
762767
_ = env.ShouldReconcile(authzReconciler, req)
763768

764769
testWorker := testutils.NewTestWorker(env.Client(testutils.CrateCluster), env.Client(testutils.APIServerCluster))
765-
controller := env.Reconciler(authzReconciler).(*authorization.AuthorizationReconciler)
770+
controller, err := testing.ReconcilerAs[*authorization.AuthorizationReconciler](env.Reconciler(authzReconciler))
771+
Expect(err).ToNot(HaveOccurred())
766772
controller.RegisterTasks(testWorker)
767773

768774
as := &openmcpv1alpha1.APIServer{}
@@ -914,7 +920,8 @@ var _ = Describe("CO-1153 Authorization Controller", func() {
914920
_ = env.ShouldReconcile(authzReconciler, req)
915921

916922
testWorker := testutils.NewTestWorker(env.Client(testutils.CrateCluster), env.Client(testutils.APIServerCluster))
917-
controller := env.Reconciler(authzReconciler).(*authorization.AuthorizationReconciler)
923+
controller, err := testing.ReconcilerAs[*authorization.AuthorizationReconciler](env.Reconciler(authzReconciler))
924+
Expect(err).ToNot(HaveOccurred())
918925
controller.RegisterTasks(testWorker)
919926

920927
as := &openmcpv1alpha1.APIServer{}

0 commit comments

Comments
 (0)