|
1 | 1 | import { CloudWatchLogs } from "@aws-sdk/client-cloudwatch-logs"; |
| 2 | +import { GetCallerIdentityCommandOutput, STS } from "@aws-sdk/client-sts"; |
2 | 3 | import { AwsJson1_1Protocol, AwsSmithyRpcV2CborProtocol } from "@aws-sdk/core/protocols"; |
3 | | -import type { IncomingMessage } from "node:http"; |
4 | 4 | import { describe, expect, test as it } from "vitest"; |
5 | 5 |
|
6 | 6 | describe( |
7 | 7 | CloudWatchLogs.name, |
| 8 | + { |
| 9 | + timeout: 120_000, |
| 10 | + retry: 4, |
| 11 | + }, |
8 | 12 | () => { |
9 | 13 | const cwlDefault = new CloudWatchLogs({ |
10 | 14 | 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 | 15 | }); |
21 | 16 |
|
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; |
25 | 21 |
|
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}`; |
35 | 24 |
|
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}`, |
39 | 27 | limit: 1, |
40 | 28 | }); |
41 | 29 |
|
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; |
43 | 41 |
|
44 | 42 | if (groupArn) { |
45 | 43 | const liveTail = await cwl.startLiveTail({ |
@@ -68,6 +66,5 @@ describe( |
68 | 66 | } |
69 | 67 | } |
70 | 68 | }); |
71 | | - }, |
72 | | - 120_000 |
| 69 | + } |
73 | 70 | ); |
0 commit comments