@@ -36,14 +36,12 @@ const createContext = (
3636) : KubernetesClient => ( {
3737 namespace : "test-ns" ,
3838 client : {
39- listNamespacedConfigMap : ( {
40- _continue,
41- } : {
39+ listNamespacedConfigMap : ( request : {
4240 namespace : string ;
4341 limit ?: number ;
44- _continue ?: string ;
42+ continue ?: string ;
4543 } ) => {
46- if ( _continue ) {
44+ if ( request . continue ) {
4745 return Promise . resolve ( { body : { items : [ ] , metadata : { } } } ) ;
4846 }
4947 return Promise . resolve ( {
@@ -56,6 +54,40 @@ const createContext = (
5654 } as unknown as KubernetesClient [ "client" ] ,
5755} ) ;
5856
57+ const createPaginatedContext = (
58+ pages : readonly ( readonly V1ConfigMap [ ] ) [ ] ,
59+ tokens : readonly ( string | undefined ) [ ]
60+ ) : KubernetesClient => {
61+ let callIndex = 0 ;
62+ return {
63+ namespace : "test-ns" ,
64+ client : {
65+ listNamespacedConfigMap : ( request : {
66+ namespace : string ;
67+ limit ?: number ;
68+ continue ?: string ;
69+ } ) => {
70+ const expectedToken = tokens [ callIndex ] ;
71+ const providedToken = request . continue ?? undefined ;
72+ if ( providedToken !== expectedToken ) {
73+ throw new Error (
74+ `Unexpected continue token: expected ${ expectedToken } , received ${ providedToken } `
75+ ) ;
76+ }
77+ const items = pages [ callIndex ] ?? [ ] ;
78+ const nextToken = tokens [ callIndex + 1 ] ;
79+ callIndex += 1 ;
80+ return Promise . resolve ( {
81+ body : {
82+ items,
83+ metadata : nextToken ? { continue : nextToken } : { } ,
84+ } ,
85+ } ) ;
86+ } ,
87+ } as unknown as KubernetesClient [ "client" ] ,
88+ } ;
89+ } ;
90+
5991describe ( "downloadAbi" , ( ) => {
6092 test ( "writes annotated configmaps to disk" , async ( ) => {
6193 const configMap : V1ConfigMap = {
@@ -103,4 +135,45 @@ describe("downloadAbi", () => {
103135 expect ( entries ) . toHaveLength ( 0 ) ;
104136 expect ( capturedOutput ) . toContain ( "No ABI ConfigMaps found" ) ;
105137 } ) ;
138+
139+ test ( "fetches all pages when the API provides a continue token" , async ( ) => {
140+ const pageOne : V1ConfigMap = {
141+ metadata : {
142+ name : "abi-first" ,
143+ annotations : {
144+ [ ARTIFACT_ANNOTATION_KEY ] : ARTIFACT_VALUES . abi ,
145+ } ,
146+ } ,
147+ data : {
148+ "First.json" : "{}\n" ,
149+ } ,
150+ } ;
151+ const pageTwo : V1ConfigMap = {
152+ metadata : {
153+ name : "abi-second" ,
154+ annotations : {
155+ [ ARTIFACT_ANNOTATION_KEY ] : ARTIFACT_VALUES . abi ,
156+ } ,
157+ } ,
158+ data : {
159+ "Second.json" : "{}\n" ,
160+ } ,
161+ } ;
162+
163+ await downloadAbi (
164+ { outputDirectory : workingDirectory } ,
165+ {
166+ createContext : ( ) =>
167+ Promise . resolve (
168+ createPaginatedContext (
169+ [ [ pageOne ] , [ pageTwo ] ] ,
170+ [ undefined , "page-2" , undefined ]
171+ )
172+ ) ,
173+ }
174+ ) ;
175+
176+ const directories = await readdir ( workingDirectory ) ;
177+ expect ( directories . sort ( ) ) . toEqual ( [ "abi-first" , "abi-second" ] ) ;
178+ } ) ;
106179} ) ;
0 commit comments