storage/testing/utils: add helper functions

Kubernetes-commit: 3a96baf3fa8e837159b27b98b05c5024143b06a3
This commit is contained in:
Lukasz Szaszkiewicz 2023-09-15 12:26:11 +02:00 committed by Kubernetes Publisher
parent a4c66a9ba7
commit 3c3bb86696
1 changed files with 23 additions and 0 deletions

View File

@ -187,6 +187,29 @@ func testCheckStop(t *testing.T, w watch.Interface) {
}
}
func testCheckResultsInStrictOrder(t *testing.T, w watch.Interface, expectedEvents []watch.Event) {
for _, expectedEvent := range expectedEvents {
testCheckResult(t, w, expectedEvent)
}
}
func testCheckResultsInRandomOrder(t *testing.T, w watch.Interface, expectedEvents []watch.Event) {
for range expectedEvents {
testCheckResultFunc(t, w, func(actualEvent watch.Event) {
ExpectContains(t, "unexpected event", toInterfaceSlice(expectedEvents), actualEvent)
})
}
}
func testCheckNoMoreResults(t *testing.T, w watch.Interface) {
select {
case e := <-w.ResultChan():
t.Errorf("Unexpected: %#v event received, expected no events", e)
case <-time.After(time.Second):
return
}
}
func toInterfaceSlice[T any](s []T) []interface{} {
result := make([]interface{}, len(s))
for i, v := range s {