Skip to content

Commit 26a22f5

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

File tree

1 file changed

+25
-28
lines changed

1 file changed

+25
-28
lines changed
Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,43 @@
11
import { CloudWatchLogs } from "@aws-sdk/client-cloudwatch-logs";
2+
import { GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts";
23
import { AwsJson1_1Protocol, AwsSmithyRpcV2CborProtocol } from "@aws-sdk/core/protocols";
3-
import type { IncomingMessage } from "node:http";
44
import { describe, expect, test as it } from "vitest";
55

66
describe(
77
CloudWatchLogs.name,
8+
{
9+
timeout: 120_000,
10+
retry: 4,
11+
},
812
() => {
913
const cwlDefault = new CloudWatchLogs({
1014
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" }),
2015
});
2116

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();
17+
it("should be able to use an event stream to tail logs", async () => {
18+
const sts = new STS({ region: "us-west-2" });
19+
const id: GetCallerIdentityCommandOutput = await sts.getCallerIdentity();
20+
const accountId = id.Account;
2521

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

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({
25+
let logGroups = await cwl.listLogGroups({
26+
logGroupNamePattern: `^${testLogGroupName}`,
3927
limit: 1,
4028
});
4129

42-
const groupArn = logGroups.logGroups?.[0].logGroupArn;
30+
if (!logGroups.logGroups?.length) {
31+
await cwl.createLogGroup({
32+
logGroupName: testLogGroupName,
33+
});
34+
logGroups = await cwl.listLogGroups({
35+
logGroupNamePattern: `^${testLogGroupName}`,
36+
limit: 1,
37+
});
38+
}
39+
40+
const groupArn = logGroups.logGroups?.[0]?.logGroupArn;
4341

4442
if (groupArn) {
4543
const liveTail = await cwl.startLiveTail({
@@ -68,6 +66,5 @@ describe(
6866
}
6967
}
7068
});
71-
},
72-
120_000
69+
}
7370
);

0 commit comments

Comments
 (0)