55 "testing"
66
77 kcpcorev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/core/v1alpha1"
8+ pmconfig "github.com/platform-mesh/golang-commons/config"
89 "k8s.io/apimachinery/pkg/types"
910 "sigs.k8s.io/controller-runtime/pkg/client"
1011 "sigs.k8s.io/controller-runtime/pkg/kontext"
@@ -18,6 +19,7 @@ import (
1819 "k8s.io/utils/ptr"
1920
2021 "github.com/platform-mesh/account-operator/api/v1alpha1"
22+ "github.com/platform-mesh/account-operator/internal/config"
2123 "github.com/platform-mesh/account-operator/pkg/subroutines"
2224 "github.com/platform-mesh/account-operator/pkg/subroutines/mocks"
2325)
@@ -51,7 +53,7 @@ func TestFGASubroutine_Finalizers(t *testing.T) {
5153
5254func TestFGASubroutine_Process (t * testing.T ) {
5355 creator := "test-creator"
54-
56+ defaultContext := pmconfig . SetConfigInContext ( context . Background (), config. OperatorConfig {})
5557 testCases := []struct {
5658 name string
5759 expectedError bool
@@ -62,7 +64,7 @@ func TestFGASubroutine_Process(t *testing.T) {
6264 }{
6365 {
6466 name : "should_fail_if_no_cluster_in_context" ,
65- ctx : context . Background () ,
67+ ctx : defaultContext ,
6668 expectedPanic : true ,
6769 account : & v1alpha1.Account {
6870 Spec : v1alpha1.AccountSpec {
@@ -80,7 +82,7 @@ func TestFGASubroutine_Process(t *testing.T) {
8082 },
8183 {
8284 name : "should_skip_processing_if_subroutine_ran_before" ,
83- ctx : kontext .WithCluster (context . Background () , "some-cluster" ),
85+ ctx : kontext .WithCluster (defaultContext , "some-cluster" ),
8486 account : & v1alpha1.Account {
8587 Spec : v1alpha1.AccountSpec {
8688 Type : v1alpha1 .AccountTypeOrg ,
@@ -129,7 +131,7 @@ func TestFGASubroutine_Process(t *testing.T) {
129131 },
130132 {
131133 name : "should_fail_if_get_store_id_fails" ,
132- ctx : kontext .WithCluster (context . Background () , "some-cluster" ),
134+ ctx : kontext .WithCluster (defaultContext , "some-cluster" ),
133135 expectedError : true ,
134136 account : & v1alpha1.Account {
135137 ObjectMeta : metav1.ObjectMeta {
@@ -168,7 +170,7 @@ func TestFGASubroutine_Process(t *testing.T) {
168170 },
169171 {
170172 name : "should_fail_if_get_parent_account_fails" ,
171- ctx : kontext .WithCluster (context . Background () , "some-cluster" ),
173+ ctx : kontext .WithCluster (defaultContext , "some-cluster" ),
172174 expectedError : true ,
173175 account : & v1alpha1.Account {
174176 ObjectMeta : metav1.ObjectMeta {
@@ -183,7 +185,7 @@ func TestFGASubroutine_Process(t *testing.T) {
183185 },
184186 {
185187 name : "should_fail_if_write_fails" ,
186- ctx : kontext .WithCluster (context . Background () , "some-cluster" ),
188+ ctx : kontext .WithCluster (defaultContext , "some-cluster" ),
187189 expectedError : true ,
188190 account : & v1alpha1.Account {
189191 ObjectMeta : metav1.ObjectMeta {
@@ -234,7 +236,7 @@ func TestFGASubroutine_Process(t *testing.T) {
234236 },
235237 {
236238 name : "should_ignore_error_if_duplicate_write_error" ,
237- ctx : kontext .WithCluster (context . Background () , "some-cluster" ),
239+ ctx : kontext .WithCluster (defaultContext , "some-cluster" ),
238240 account : & v1alpha1.Account {
239241 ObjectMeta : metav1.ObjectMeta {
240242 Name : "test-account" ,
@@ -286,7 +288,7 @@ func TestFGASubroutine_Process(t *testing.T) {
286288 },
287289 {
288290 name : "should_succeed" ,
289- ctx : kontext .WithCluster (context . Background () , "some-cluster" ),
291+ ctx : kontext .WithCluster (defaultContext , "some-cluster" ),
290292 account : & v1alpha1.Account {
291293 ObjectMeta : metav1.ObjectMeta {
292294 Name : "test-account" ,
@@ -337,7 +339,7 @@ func TestFGASubroutine_Process(t *testing.T) {
337339 },
338340 {
339341 name : "should_succeed_with_creator_for_sa" ,
340- ctx : kontext .WithCluster (context . Background () , "some-cluster" ),
342+ ctx : kontext .WithCluster (defaultContext , "some-cluster" ),
341343 account : & v1alpha1.Account {
342344 ObjectMeta : metav1.ObjectMeta {
343345 Name : "test-account" ,
@@ -397,7 +399,7 @@ func TestFGASubroutine_Process(t *testing.T) {
397399 },
398400 {
399401 name : "should_fail_with_creator_in_sa_range" ,
400- ctx : kontext .WithCluster (context . Background () , "some-cluster" ),
402+ ctx : kontext .WithCluster (defaultContext , "some-cluster" ),
401403 expectedError : true ,
402404 account : & v1alpha1.Account {
403405 ObjectMeta : metav1.ObjectMeta {
@@ -448,7 +450,7 @@ func TestFGASubroutine_Process(t *testing.T) {
448450 },
449451 {
450452 name : "should_succeed_with_creator" ,
451- ctx : kontext .WithCluster (context . Background () , "some-cluster" ),
453+ ctx : kontext .WithCluster (defaultContext , "some-cluster" ),
452454 account : & v1alpha1.Account {
453455 ObjectMeta : metav1.ObjectMeta {
454456 Name : "test-account" ,
@@ -789,7 +791,7 @@ func TestCreatorSubroutine_Finalize(t *testing.T) {
789791 },
790792 },
791793 }
792-
794+ defaultContext := pmconfig . SetConfigInContext ( context . Background (), config. OperatorConfig {})
793795 for _ , test := range testCases {
794796 t .Run (test .name , func (t * testing.T ) {
795797
@@ -801,7 +803,7 @@ func TestCreatorSubroutine_Finalize(t *testing.T) {
801803 }
802804
803805 routine := subroutines .NewFGASubroutine (k8sClient , openFGAClient , "owner" , "parent" , "account" )
804- ctx := kontext .WithCluster (context . Background () , "abcdefghi" )
806+ ctx := kontext .WithCluster (defaultContext , "abcdefghi" )
805807 _ , err := routine .Finalize (ctx , test .account )
806808 if test .expectedError {
807809 assert .NotNil (t , err )
0 commit comments