Skip to content

Commit 0aab205

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

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-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: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { CloudWatchLogs } from "@aws-sdk/client-cloudwatch-logs";
2+
import { AwsJson1_1Protocol, AwsSmithyRpcV2CborProtocol } from "@aws-sdk/core/protocols";
3+
import { describe, expect, test as it } from "vitest";
4+
5+
describe(
6+
CloudWatchLogs.name,
7+
() => {
8+
const cwlDefault = new CloudWatchLogs({
9+
region: "us-west-2",
10+
protocol: new AwsJson1_1Protocol({
11+
defaultNamespace: "com.amazonaws.cloudwatchlogs",
12+
serviceTarget: "Logs_20140328",
13+
awsQueryCompatible: false,
14+
}),
15+
});
16+
const cwlCustom = new CloudWatchLogs({
17+
region: "us-west-2",
18+
protocol: new AwsSmithyRpcV2CborProtocol({ defaultNamespace: "com.amazonaws.cloudwatchlogs" }),
19+
});
20+
21+
it("should be able to make requests with runtime protocol selection", async () => {
22+
for (const cwl of [cwlDefault, cwlCustom]) {
23+
const logGroups = await cwl.listLogGroups();
24+
25+
expect(logGroups).toMatchObject({
26+
$metadata: {
27+
httpStatusCode: 200,
28+
},
29+
logGroups: expect.any(Array),
30+
});
31+
expect(logGroups.nextToken ?? "").toBeTypeOf("string");
32+
}
33+
});
34+
35+
it("should be able to use an event stream to tail logs", async () => {
36+
for (const cwl of [cwlDefault, cwlCustom]) {
37+
const logGroups = await cwl.listLogGroups({
38+
limit: 1,
39+
});
40+
41+
const groupArn = logGroups.logGroups?.[0].logGroupArn;
42+
43+
if (groupArn) {
44+
const liveTail = await cwl.startLiveTail({
45+
logGroupIdentifiers: [groupArn],
46+
});
47+
48+
let pagesRead = 0;
49+
50+
for await (const page of liveTail.responseStream ?? []) {
51+
pagesRead += 1;
52+
53+
if (pagesRead === 1) {
54+
expect(page.sessionStart?.requestId).toBeTypeOf("string");
55+
expect(page.sessionStart?.sessionId).toBeTypeOf("string");
56+
expect(page.sessionStart?.logGroupIdentifiers).toEqual([groupArn]);
57+
} else if (pagesRead === 2) {
58+
expect(page.sessionUpdate?.sessionMetadata).toMatchObject({
59+
sampled: expect.any(Boolean),
60+
});
61+
} else if (pagesRead > 2) {
62+
break;
63+
}
64+
}
65+
}
66+
}
67+
});
68+
},
69+
120_000
70+
);
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)