fix status settings

This commit is contained in:
kkb0318
2024-07-18 23:36:28 +09:00
parent 589f9afc2e
commit de5d43f523
2 changed files with 43 additions and 1 deletions
+1 -1
View File
@@ -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
})
}
+42
View File
@@ -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)
})
}
}