From dd5562bc6ca63222a84932d373d711926e21e933 Mon Sep 17 00:00:00 2001 From: Michael Burt Date: Mon, 14 Apr 2025 13:57:43 -0600 Subject: [PATCH 1/3] Fix test assertion for paginated results --- internal/remote/query_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/remote/query_test.go b/internal/remote/query_test.go index 01601fa8..5f2d6592 100644 --- a/internal/remote/query_test.go +++ b/internal/remote/query_test.go @@ -112,6 +112,6 @@ func TestListPagination(t *testing.T) { actual := len(objs) if int(totalItemsInList) != actual { t.Logf("expected items to be %d but found %d. Change this to Fatal when https://github.com/kubernetes/kubernetes/issues/107277 is fixed", totalItemsInList, actual) - // t.Fatalf("expected items to be %d but found %d", totalItemsInList, actual) + t.Fatalf("expected items to be %d but found %d", totalItemsInList, actual) } } From 430a2ccfdce8cd66773e7443d48b0f165d957653 Mon Sep 17 00:00:00 2001 From: Michael Burt Date: Thu, 11 Jun 2026 19:47:39 -0600 Subject: [PATCH 2/3] Fix pagination test: use string continue token and restore fatal assertion The fake dynamic client's GetContinue() reads the continue field via getNestedString, which returns "" for non-string values. Storing the continue value as int64 caused FollowContinue to stop after the first page. Switch to a non-empty string token for pages with remaining items. Also remove the t.Logf workaround left from the upstream k8s bug (kubernetes/kubernetes#107277, fixed in k8s v1.26); the assertion is now fully enforced. Co-Authored-By: Claude Opus 4.7 --- internal/remote/query_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/remote/query_test.go b/internal/remote/query_test.go index 5f2d6592..b5496749 100644 --- a/internal/remote/query_test.go +++ b/internal/remote/query_test.go @@ -30,7 +30,7 @@ import ( "k8s.io/kubectl/pkg/scheme" ) -func newUnstructuredList(apiVersion, kind string, continueVal int64, items ...*unstructured.Unstructured) *unstructured.UnstructuredList { +func newUnstructuredList(apiVersion, kind string, continueVal string, items ...*unstructured.Unstructured) *unstructured.UnstructuredList { list := &unstructured.UnstructuredList{ Object: map[string]interface{}{ "apiVersion": apiVersion, @@ -83,7 +83,12 @@ func TestListPagination(t *testing.T) { if callIndex >= totalItemsInList { return true, nil, errors.New("unexpected call to list. list has been served already") } - listWithContinue := newUnstructuredList("v1", "SecretList", totalItemsInList-callIndex-1, uns[callIndex]) + remaining := totalItemsInList - callIndex - 1 + continueToken := "" + if remaining > 0 { + continueToken = fmt.Sprintf("page-%d", callIndex+1) + } + listWithContinue := newUnstructuredList("v1", "SecretList", continueToken, uns[callIndex]) callIndex++ return true, listWithContinue, nil }) @@ -111,7 +116,6 @@ func TestListPagination(t *testing.T) { } actual := len(objs) if int(totalItemsInList) != actual { - t.Logf("expected items to be %d but found %d. Change this to Fatal when https://github.com/kubernetes/kubernetes/issues/107277 is fixed", totalItemsInList, actual) t.Fatalf("expected items to be %d but found %d", totalItemsInList, actual) } } From 6d2a66184d0198572e321f0d515d4d8cf3b36863 Mon Sep 17 00:00:00 2001 From: Michael Burt Date: Thu, 11 Jun 2026 20:26:39 -0600 Subject: [PATCH 3/3] Clean up pagination test helpers - Fix off-by-one in uns slice creation (< instead of <=) - Use SetContinue() in newUnstructuredList instead of storing "" explicitly - Simplify continue token condition to callIndex+1 < totalItemsInList Co-Authored-By: Claude Opus 4.7 --- internal/remote/query_test.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/remote/query_test.go b/internal/remote/query_test.go index b5496749..8e26bb70 100644 --- a/internal/remote/query_test.go +++ b/internal/remote/query_test.go @@ -35,11 +35,10 @@ func newUnstructuredList(apiVersion, kind string, continueVal string, items ...* Object: map[string]interface{}{ "apiVersion": apiVersion, "kind": kind, - "metadata": map[string]interface{}{ - "continue": continueVal, - }, + "metadata": map[string]interface{}{}, }, } + list.SetContinue(continueVal) for i := range items { list.Items = append(list.Items, *items[i]) } @@ -74,7 +73,7 @@ func TestListPagination(t *testing.T) { tf.FakeDynamicClient = dynamicfakeclient.NewSimpleDynamicClientWithCustomListKinds(scheme.Scheme, listMapping) var uns []*unstructured.Unstructured var totalItemsInList = int64(3) - for i := int64(0); i <= totalItemsInList; i++ { + for i := int64(0); i < totalItemsInList; i++ { ns := "default" uns = append(uns, newUnstructured("v1", "Secret", ns, fmt.Sprintf("test-secret-%d", i))) } @@ -83,9 +82,8 @@ func TestListPagination(t *testing.T) { if callIndex >= totalItemsInList { return true, nil, errors.New("unexpected call to list. list has been served already") } - remaining := totalItemsInList - callIndex - 1 continueToken := "" - if remaining > 0 { + if callIndex+1 < totalItemsInList { continueToken = fmt.Sprintf("page-%d", callIndex+1) } listWithContinue := newUnstructuredList("v1", "SecretList", continueToken, uns[callIndex])