Skip to content

Commit d1a7007

Browse files
committed
test: create log group if none exists
1 parent 6cad22b commit d1a7007

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed
Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
11
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";
2+
import { GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
43
import { describe, expect, test as it } from "vitest";
54

65
describe(
76
CloudWatchLogs.name,
7+
{
8+
timeout: 120_000,
9+
retry: 4,
10+
},
811
() => {
912
const cwlDefault = new CloudWatchLogs({
1013
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" }),
2014
});
2115

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();
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;
2520

26-
expect(logGroups).toMatchObject({
27-
$metadata: {
28-
httpStatusCode: 200,
29-
},
30-
logGroups: expect.any(Array),
31-
});
32-
expect(logGroups.nextToken ?? "").toBeTypeOf("string");
33-
}
34-
});
21+
for (const cwl of [cwlDefault]) {
22+
const testLogGroupName = `/jsv3-e2e-${accountId}`;
3523

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({
24+
let logGroups = await cwl.listLogGroups({
25+
logGroupNamePattern: `^${testLogGroupName}`,
3926
limit: 1,
4027
});
4128

42-
const groupArn = logGroups.logGroups?.[0].logGroupArn;
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;
4340

4441
if (groupArn) {
4542
const liveTail = await cwl.startLiveTail({
@@ -68,6 +65,5 @@ describe(
6865
}
6966
}
7067
});
71-
},
72-
120_000
68+
}
7369
);

0 commit comments

Comments
 (0)