diff --git a/api/v1alpha1/irsa_types.go b/api/v1alpha1/irsa_types.go index 5145697..b6ade49 100644 --- a/api/v1alpha1/irsa_types.go +++ b/api/v1alpha1/irsa_types.go @@ -87,7 +87,7 @@ type StatusServiceAccountList []IRSANamespacedNameWithTags func (s *StatusServiceAccountList) IsExist(nsNames types.NamespacedName) bool { return slices.ContainsFunc(*s, func(sa IRSANamespacedNameWithTags) bool { - return sa.Name == nsNames.Name && sa.Name == nsNames.Namespace + return sa.Name == nsNames.Name && sa.Namespace == nsNames.Namespace }) } diff --git a/api/v1alpha1/irsa_types_test.go b/api/v1alpha1/irsa_types_test.go index cadf3fa..46b1496 100644 --- a/api/v1alpha1/irsa_types_test.go +++ b/api/v1alpha1/irsa_types_test.go @@ -83,3 +83,45 @@ func TestStatusServiceAccountList_Delete(t *testing.T) { }) } } + +func TestStatusServiceAccountList_IsExist(t *testing.T) { + tests := []struct { + name string + initial StatusServiceAccountList + toCheck types.NamespacedName + expected bool + }{ + { + name: "Item exists", + initial: StatusServiceAccountList{ + {Name: "existing", Namespace: "default"}, + {Name: "another", Namespace: "default"}, + }, + toCheck: types.NamespacedName{Name: "existing", Namespace: "default"}, + expected: true, + }, + { + name: "Item does not exist", + initial: StatusServiceAccountList{ + {Name: "existing", Namespace: "default"}, + }, + toCheck: types.NamespacedName{Name: "nonexisting", Namespace: "default"}, + expected: false, + }, + { + name: "Item with different namespace", + initial: StatusServiceAccountList{ + {Name: "existing", Namespace: "default"}, + }, + toCheck: types.NamespacedName{Name: "existing", Namespace: "othernamespace"}, + expected: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := tt.initial.IsExist(tt.toCheck) + assert.Equal(t, tt.expected, result) + }) + } +}