add unit test and documentation for finalizers (#2509)

* add unit test and documentation for finalizers
* error msg with lower case and cover sync case
* try to avoid adding json-patch dependency
* use Update to remove finalizer
* changing status and finalizer during create
* do not call Delete() twice
This commit is contained in:
Felix Kunde
2024-01-22 12:13:40 +01:00
committed by GitHub
parent 3bad9aaded
commit 4a0c483514
14 changed files with 245 additions and 118 deletions
+20
View File
@@ -66,6 +66,17 @@ var substractTest = []struct {
{[]string{"a"}, []string{""}, []string{"a"}, false},
}
var removeStringTest = []struct {
slice []string
item string
result []string
}{
{[]string{"a", "b", "c"}, "b", []string{"a", "c"}},
{[]string{"a"}, "b", []string{"a"}},
{[]string{"a"}, "a", []string{}},
{[]string{}, "a", []string{}},
}
var sliceContaintsTest = []struct {
slice []string
item string
@@ -200,6 +211,15 @@ func TestFindNamedStringSubmatch(t *testing.T) {
}
}
func TestRemoveString(t *testing.T) {
for _, tt := range removeStringTest {
res := RemoveString(tt.slice, tt.item)
if !IsEqualIgnoreOrder(res, tt.result) {
t.Errorf("RemoveString expected: %#v, got: %#v", tt.result, res)
}
}
}
func TestSliceContains(t *testing.T) {
for _, tt := range sliceContaintsTest {
res := SliceContains(tt.slice, tt.item)