Skip to content

Commit 925eb24

Browse files
committed
fix(download-abi): update request parameter for listNamespacedConfigMap
- Changed the `_continue` parameter to `continue` in the request object for the `listNamespacedConfigMap` method to align with the updated KubernetesClient interface. - Enhanced the test suite for the `download-abi` command to ensure proper handling of pagination tokens and verify that all pages are fetched correctly.
1 parent cb24282 commit 925eb24

File tree

2 files changed

+92
-9
lines changed

2 files changed

+92
-9
lines changed

src/cli/commands/download-abi/download-abi.command.test.ts

Lines changed: 78 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5991
describe("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
});

src/cli/commands/download-abi/download-abi.command.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,28 @@ const writeConfigMap = async (
123123
return written;
124124
};
125125

126+
const PAGE_SIZE = 100;
127+
126128
const fetchAbiConfigMaps = async (
127129
context: KubernetesClient
128130
): Promise<readonly V1ConfigMap[]> => {
129131
const abis: V1ConfigMap[] = [];
130132
let continueToken: string | undefined;
131133

132134
do {
133-
const response = await context.client.listNamespacedConfigMap({
135+
const request: {
136+
namespace: string;
137+
limit: number;
138+
continue?: string;
139+
} = {
134140
namespace: context.namespace,
135-
limit: 100,
136-
_continue: continueToken,
137-
});
141+
limit: PAGE_SIZE,
142+
};
143+
if (continueToken) {
144+
request.continue = continueToken;
145+
}
146+
147+
const response = await context.client.listNamespacedConfigMap(request);
138148
const items = toConfigMapList(response);
139149
for (const item of items) {
140150
const annotation = item.metadata?.annotations?.[ARTIFACT_ANNOTATION_KEY];

0 commit comments

Comments
 (0)