From e72664861e1ebb27b934f4c626a46148d7c53521 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Mon, 20 Nov 2023 11:28:20 +0100 Subject: [PATCH] fix Signed-off-by: odubajDT --- common/flagdinjector/flagdinjector_test.go | 54 +++------------------- 1 file changed, 7 insertions(+), 47 deletions(-) diff --git a/common/flagdinjector/flagdinjector_test.go b/common/flagdinjector/flagdinjector_test.go index 7518f2196..41c7367dc 100644 --- a/common/flagdinjector/flagdinjector_test.go +++ b/common/flagdinjector/flagdinjector_test.go @@ -1035,60 +1035,20 @@ func Test_getSecurityContext(t *testing.T) { } } -//nolint:dupl func TestFlagdContainerInjector_EnableClusterRoleBinding_AddDefaultServiceAccountName(t *testing.T) { - - namespace, fakeClient := initEnableClusterroleBindingTestEnv() - - serviceAccount := &v1.ServiceAccount{ - ObjectMeta: metav1.ObjectMeta{ - Name: "default", - Namespace: namespace, - }, - } - - crb := &rbacv1.ClusterRoleBinding{ - ObjectMeta: metav1.ObjectMeta{ - Name: constant.ClusterRoleBindingName, - }, - } - - err := fakeClient.Create(context.Background(), serviceAccount) - require.Nil(t, err) - - err = fakeClient.Create(context.Background(), crb) - require.Nil(t, err) - - fi := &FlagdContainerInjector{ - Client: fakeClient, - Logger: testr.New(t), - FlagdProxyConfig: getProxyConfig(), - FlagDResourceRequirements: getResourceRequirements(), - Image: testImage, - Tag: testTag, - } - - err = fi.EnableClusterRoleBinding(context.Background(), namespace, "") - require.Nil(t, err) - - updatedCrb := &rbacv1.ClusterRoleBinding{} - err = fakeClient.Get(context.Background(), client.ObjectKey{Name: crb.Name}, updatedCrb) - - require.Nil(t, err) - - require.Len(t, updatedCrb.Subjects, 1) - require.Equal(t, "default", updatedCrb.Subjects[0].Name) - require.Equal(t, namespace, updatedCrb.Subjects[0].Namespace) + enableClusterRoleBindingTest(t, "default", "") } -//nolint:dupl func TestFlagdContainerInjector_EnableClusterRoleBinding_ServiceAccountName(t *testing.T) { + enableClusterRoleBindingTest(t, "my-serviceaccount", "my-serviceaccount") +} +func enableClusterRoleBindingTest(t *testing.T, name string, input string) { namespace, fakeClient := initEnableClusterroleBindingTestEnv() serviceAccount := &v1.ServiceAccount{ ObjectMeta: metav1.ObjectMeta{ - Name: "my-serviceaccount", + Name: name, Namespace: namespace, }, } @@ -1114,7 +1074,7 @@ func TestFlagdContainerInjector_EnableClusterRoleBinding_ServiceAccountName(t *t Tag: testTag, } - err = fi.EnableClusterRoleBinding(context.Background(), namespace, "my-serviceaccount") + err = fi.EnableClusterRoleBinding(context.Background(), namespace, input) require.Nil(t, err) updatedCrb := &rbacv1.ClusterRoleBinding{} @@ -1123,7 +1083,7 @@ func TestFlagdContainerInjector_EnableClusterRoleBinding_ServiceAccountName(t *t require.Nil(t, err) require.Len(t, updatedCrb.Subjects, 1) - require.Equal(t, "my-serviceaccount", updatedCrb.Subjects[0].Name) + require.Equal(t, name, updatedCrb.Subjects[0].Name) require.Equal(t, namespace, updatedCrb.Subjects[0].Namespace) }