Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <[email protected]>
  • Loading branch information
odubajDT committed Nov 20, 2023
1 parent bbb42d4 commit e726648
Showing 1 changed file with 7 additions and 47 deletions.
54 changes: 7 additions & 47 deletions common/flagdinjector/flagdinjector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
Expand All @@ -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{}
Expand All @@ -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)
}

Expand Down

0 comments on commit e726648

Please sign in to comment.