|
1 | 1 | 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"; |
4 | 3 | import { describe, expect, test as it } from "vitest"; |
5 | 4 |
|
6 | 5 | describe( |
7 | 6 | CloudWatchLogs.name, |
| 7 | + { |
| 8 | + timeout: 120_000, |
| 9 | + retry: 4, |
| 10 | + }, |
8 | 11 | () => { |
9 | 12 | const cwlDefault = new CloudWatchLogs({ |
10 | 13 | 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 | 14 | }); |
21 | 15 |
|
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; |
25 | 20 |
|
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}`; |
35 | 23 |
|
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}`, |
39 | 26 | limit: 1, |
40 | 27 | }); |
41 | 28 |
|
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; |
43 | 40 |
|
44 | 41 | if (groupArn) { |
45 | 42 | const liveTail = await cwl.startLiveTail({ |
@@ -68,6 +65,5 @@ describe( |
68 | 65 | } |
69 | 66 | } |
70 | 67 | }); |
71 | | - }, |
72 | | - 120_000 |
| 68 | + } |
73 | 69 | ); |
0 commit comments