Skip to content

Commit 13e3bb1

Browse files
millotpFluf22
authored andcommitted
support multiple lang
1 parent 9ed43f0 commit 13e3bb1

File tree

7 files changed

+58
-398
lines changed

7 files changed

+58
-398
lines changed

scripts/cts/runCts.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { startTestServer } from './testServer';
99
import { assertChunkWrapperValid } from './testServer/chunkWrapper.js';
1010
import { assertValidReplaceAllObjects } from './testServer/replaceAllObjects.js';
1111
import { assertValidTimeouts } from './testServer/timeout.js';
12+
import { assertValidWaitForApiKey } from './testServer/waitForApiKey.js';
1213

1314
async function runCtsOne(
1415
language: Language,
@@ -147,5 +148,6 @@ export async function runCts(
147148
assertValidTimeouts(languages.length);
148149
assertChunkWrapperValid(languages.length - skip('dart') - skip('scala'));
149150
assertValidReplaceAllObjects(languages.length - skip('dart') - skip('scala'));
151+
assertValidWaitForApiKey(languages.length - skip('dart') - skip('scala'));
150152
}
151153
}

scripts/cts/testServer/waitForApiKey.ts

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,45 @@
11
import type { Server } from 'http';
22

3+
import { expect } from 'chai';
34
import type { Express } from 'express';
45

56
import { setupServer } from '.';
67

7-
const retryCount = {
8-
add: 0,
9-
update: 0,
10-
delete: 0,
11-
};
8+
const retryCount: Record<
9+
string,
10+
{
11+
add: number;
12+
update: number;
13+
delete: number;
14+
}
15+
> = {};
16+
17+
export function assertValidWaitForApiKey(expectedCount: number): void {
18+
expect(Object.keys(retryCount).length).to.be.equal(expectedCount);
19+
for (const retry of Object.values(retryCount)) {
20+
expect(retry).to.deep.equal({
21+
add: 0,
22+
update: 0,
23+
delete: 0,
24+
});
25+
}
26+
}
1227

1328
function addRoutes(app: Express): void {
1429
app.get('/1/keys/:key', (req, res) => {
15-
if (req.params.key === 'api-key-add-operation-test') {
16-
if (retryCount.add < 3) {
30+
const lang = req.params.key.split('-').at(-1) as string;
31+
if (!retryCount[lang]) {
32+
retryCount[lang] = {
33+
add: 0,
34+
update: 0,
35+
delete: 0,
36+
};
37+
}
38+
const retry = retryCount[lang];
39+
if (req.params.key === `api-key-add-operation-test-${lang}`) {
40+
if (retry.add < 3) {
1741
res.status(404).json({ message: `API key doesn't exist` });
18-
} else if (retryCount.add === 3) {
42+
} else if (retry.add === 3) {
1943
res.status(200).json({
2044
value: req.params.key,
2145
description: 'my new api key',
@@ -26,16 +50,15 @@ function addRoutes(app: Express): void {
2650
createdAt: 1720094400,
2751
});
2852

29-
retryCount.add = -1;
53+
retry.add = -1;
3054
} else {
31-
// eslint-disable-next-line no-console
32-
console.error(`Invalid retry count: ${retryCount.add}`);
33-
res.status(500).json({ message: `Internal Server Error` });
55+
expect(retry.add).to.be.lessThan(3);
56+
return;
3457
}
3558

36-
retryCount.add += 1;
37-
} else if (req.params.key === 'api-key-update-operation-test') {
38-
if (retryCount.update < 3) {
59+
retry.add += 1;
60+
} else if (req.params.key === `api-key-update-operation-test-${lang}`) {
61+
if (retry.update < 3) {
3962
res.status(200).json({
4063
value: req.params.key,
4164
description: 'my new api key',
@@ -45,7 +68,7 @@ function addRoutes(app: Express): void {
4568
maxHitsPerQuery: 20,
4669
createdAt: 1720094400,
4770
});
48-
} else if (retryCount.update === 3) {
71+
} else if (retry.update === 3) {
4972
res.status(200).json({
5073
value: req.params.key,
5174
description: 'my updated api key',
@@ -56,16 +79,15 @@ function addRoutes(app: Express): void {
5679
createdAt: 1720094400,
5780
});
5881

59-
retryCount.update = -1;
82+
retry.update = -1;
6083
} else {
61-
// eslint-disable-next-line no-console
62-
console.error(`Invalid retry count: ${retryCount.update}`);
63-
res.status(500).json({ message: `Internal Server Error` });
84+
expect(retry.update).to.be.lessThan(3);
85+
return;
6486
}
6587

66-
retryCount.update += 1;
67-
} else if (req.params.key === 'api-key-delete-operation-test') {
68-
if (retryCount.delete < 3) {
88+
retry.update += 1;
89+
} else if (req.params.key === `api-key-delete-operation-test-${lang}`) {
90+
if (retry.delete < 3) {
6991
res.status(200).json({
7092
value: req.params.key,
7193
description: 'my updated api key',
@@ -75,36 +97,20 @@ function addRoutes(app: Express): void {
7597
maxHitsPerQuery: 20,
7698
createdAt: 1720094400,
7799
});
78-
} else if (retryCount.delete === 3) {
100+
} else if (retry.delete === 3) {
79101
res.status(404).json({ message: `API key doesn't exist` });
80102

81-
retryCount.delete = -1;
103+
retry.delete = -1;
82104
} else {
83-
// eslint-disable-next-line no-console
84-
console.error(`Invalid retry count: ${retryCount.delete}`);
85-
res.status(500).json({ message: `Internal Server Error` });
105+
expect(retry.delete).to.be.lessThan(3);
106+
return;
86107
}
87108

88-
retryCount.delete += 1;
109+
retry.delete += 1;
89110
} else {
90-
// eslint-disable-next-line no-console
91-
console.error(`Invalid API key ${req.params.key}`);
92-
res.status(500).json({ message: `Internal Server Error` });
111+
throw new Error(`Invalid API key ${req.params.key}`);
93112
}
94113
});
95-
96-
// fallback route
97-
app.use((req, res) => {
98-
// eslint-disable-next-line no-console
99-
console.log('fallback route', req.method, req.url);
100-
res.status(500).json({ message: `Internal Server Error (fallback)` });
101-
});
102-
103-
app.use((err, req, res, _) => {
104-
// eslint-disable-next-line no-console
105-
console.error(err.message);
106-
res.status(500).send({ message: err.message });
107-
});
108114
}
109115

110116
export function waitForApiKeyServer(): Promise<Server> {

tests/CTS/client/search/helpers.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,13 @@
389389
"object": "$client",
390390
"path": "waitForApiKey",
391391
"parameters": {
392-
"key": "api-key-add-operation-test",
392+
"key": "api-key-add-operation-test-${{languageCased}}",
393393
"operation": "add"
394394
},
395395
"expected": {
396396
"type": "response",
397397
"match": {
398-
"value": "api-key-add-operation-test",
398+
"value": "api-key-add-operation-test-${{languageCased}}",
399399
"description": "my new api key",
400400
"acl": [
401401
"search",
@@ -432,7 +432,7 @@
432432
"object": "$client",
433433
"path": "waitForApiKey",
434434
"parameters": {
435-
"key": "api-key-update-operation-test",
435+
"key": "api-key-update-operation-test-${{languageCased}}",
436436
"operation": "update",
437437
"apiKey": {
438438
"description": "my updated api key",
@@ -449,7 +449,7 @@
449449
"expected": {
450450
"type": "response",
451451
"match": {
452-
"value": "api-key-update-operation-test",
452+
"value": "api-key-update-operation-test-${{languageCased}}",
453453
"description": "my updated api key",
454454
"acl": [
455455
"search",
@@ -487,7 +487,7 @@
487487
"object": "$client",
488488
"path": "waitForApiKey",
489489
"parameters": {
490-
"key": "api-key-delete-operation-test",
490+
"key": "api-key-delete-operation-test-${{languageCased}}",
491491
"operation": "delete"
492492
},
493493
"expected": {
Binary file not shown.

tests/output/java/gradle/wrapper/gradle-wrapper.properties

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)