Skip to content

Commit 6cad22b

Browse files
committed
test(client-cloudwatch-logs): e2e test for protocol selection and event streams
1 parent 78a69dc commit 6cad22b

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

clients/client-cloudwatch-logs/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
1212
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
1313
"extract:docs": "api-extractor run --local",
14-
"generate:client": "node ../../scripts/generate-clients/single-service --solo cloudwatch-logs"
14+
"generate:client": "node ../../scripts/generate-clients/single-service --solo cloudwatch-logs",
15+
"test:e2e": "yarn g:vitest run -c vitest.config.e2e.mts",
16+
"test:e2e:watch": "yarn g:vitest watch -c vitest.config.e2e.mts"
1517
},
1618
"main": "./dist-cjs/index.js",
1719
"types": "./dist-types/index.d.ts",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { CloudWatchLogs } from "@aws-sdk/client-cloudwatch-logs";
2+
import { AwsJson1_1Protocol, AwsSmithyRpcV2CborProtocol } from "@aws-sdk/core/protocols";
3+
import type { IncomingMessage } from "node:http";
4+
import { describe, expect, test as it } from "vitest";
5+
6+
describe(
7+
CloudWatchLogs.name,
8+
() => {
9+
const cwlDefault = new CloudWatchLogs({
10+
region: "us-west-2",
11+
protocol: new AwsJson1_1Protocol({
12+
defaultNamespace: "com.amazonaws.cloudwatchlogs",
13+
serviceTarget: "Logs_20140328",
14+
awsQueryCompatible: false,
15+
}),
16+
});
17+
const cwlCustom = new CloudWatchLogs({
18+
region: "us-west-2",
19+
protocol: new AwsSmithyRpcV2CborProtocol({ defaultNamespace: "com.amazonaws.cloudwatchlogs" }),
20+
});
21+
22+
it("should be able to make requests with runtime protocol selection", async () => {
23+
for (const cwl of [cwlDefault, cwlCustom]) {
24+
const logGroups = await cwl.listLogGroups();
25+
26+
expect(logGroups).toMatchObject({
27+
$metadata: {
28+
httpStatusCode: 200,
29+
},
30+
logGroups: expect.any(Array),
31+
});
32+
expect(logGroups.nextToken ?? "").toBeTypeOf("string");
33+
}
34+
});
35+
36+
it("should be able to use an event stream to tail logs", async () => {
37+
for (const cwl of [cwlDefault, cwlCustom]) {
38+
const logGroups = await cwl.listLogGroups({
39+
limit: 1,
40+
});
41+
42+
const groupArn = logGroups.logGroups?.[0].logGroupArn;
43+
44+
if (groupArn) {
45+
const liveTail = await cwl.startLiveTail({
46+
logGroupIdentifiers: [groupArn],
47+
});
48+
49+
let pagesRead = 0;
50+
51+
for await (const page of liveTail.responseStream ?? []) {
52+
pagesRead += 1;
53+
54+
if (pagesRead === 1) {
55+
expect(page.sessionStart?.requestId).toBeTypeOf("string");
56+
expect(page.sessionStart?.sessionId).toBeTypeOf("string");
57+
expect(page.sessionStart?.logGroupIdentifiers).toEqual([groupArn]);
58+
} else if (pagesRead === 2) {
59+
expect(page.sessionUpdate?.sessionMetadata).toMatchObject({
60+
sampled: expect.any(Boolean),
61+
});
62+
} else if (pagesRead > 2) {
63+
break;
64+
}
65+
}
66+
67+
cwl.destroy();
68+
}
69+
}
70+
});
71+
},
72+
120_000
73+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "vitest/config";
2+
3+
export default defineConfig({
4+
test: {
5+
exclude: ["**/*.browser.e2e.spec.ts"],
6+
include: ["**/*.e2e.spec.ts"],
7+
environment: "node",
8+
},
9+
mode: "development",
10+
});

0 commit comments

Comments
 (0)