From 3a96baf3fa8e837159b27b98b05c5024143b06a3 Mon Sep 17 00:00:00 2001 From: Lukasz Szaszkiewicz Date: Fri, 15 Sep 2023 12:26:11 +0200 Subject: [PATCH] storage/testing/utils: add helper functions --- .../apiserver/pkg/storage/testing/utils.go | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/staging/src/k8s.io/apiserver/pkg/storage/testing/utils.go b/staging/src/k8s.io/apiserver/pkg/storage/testing/utils.go index d5b6d608dfc..5d1fb3aa8b5 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/testing/utils.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/testing/utils.go @@ -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 {