Skip to content

Commit 3d7ac16

Browse files
authored
test(client-cloudwatch-logs): e2e test for live tail event streams (#7484)
* test(client-cloudwatch-logs): e2e test for protocol selection and event streams * test: create log group if none exists
1 parent cbdbdf8 commit 3d7ac16

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-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: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { CloudWatchLogs } from "@aws-sdk/client-cloudwatch-logs";
2+
import { GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
3+
import { describe, expect, test as it } from "vitest";
4+
5+
describe(
6+
CloudWatchLogs.name,
7+
{
8+
timeout: 120_000,
9+
retry: 4,
10+
},
11+
() => {
12+
const cwlDefault = new CloudWatchLogs({
13+
region: "us-west-2",
14+
});
15+
16+
it("should be able to use an event stream to tail logs", async () => {
17+
const sts = new STS({ region: "us-west-2" });
18+
const id: GetCallerIdentityCommandOutput = await sts.getCallerIdentity();
19+
const accountId = id.Account;
20+
21+
for (const cwl of [cwlDefault]) {
22+
const testLogGroupName = `/jsv3-e2e-${accountId}`;
23+
24+
let logGroups = await cwl.listLogGroups({
25+
logGroupNamePattern: `^${testLogGroupName}`,
26+
limit: 1,
27+
});
28+
29+
if (!logGroups.logGroups?.length) {
30+
await cwl.createLogGroup({
31+
logGroupName: testLogGroupName,
32+
});
33+
logGroups = await cwl.listLogGroups({
34+
logGroupNamePattern: `^${testLogGroupName}`,
35+
limit: 1,
36+
});
37+
}
38+
39+
const groupArn = logGroups.logGroups?.[0]?.logGroupArn;
40+
41+
if (groupArn) {
42+
const liveTail = await cwl.startLiveTail({
43+
logGroupIdentifiers: [groupArn],
44+
});
45+
46+
let pagesRead = 0;
47+
48+
for await (const page of liveTail.responseStream ?? []) {
49+
pagesRead += 1;
50+
51+
if (pagesRead === 1) {
52+
expect(page.sessionStart?.requestId).toBeTypeOf("string");
53+
expect(page.sessionStart?.sessionId).toBeTypeOf("string");
54+
expect(page.sessionStart?.logGroupIdentifiers).toEqual([groupArn]);
55+
} else if (pagesRead === 2) {
56+
expect(page.sessionUpdate?.sessionMetadata).toMatchObject({
57+
sampled: expect.any(Boolean),
58+
});
59+
} else if (pagesRead > 2) {
60+
break;
61+
}
62+
}
63+
64+
cwl.destroy();
65+
}
66+
}
67+
});
68+
}
69+
);
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)