|
| 1 | +import { requireRequestsFrom } from "@aws-sdk/aws-util-test/src"; |
| 2 | +import { |
| 3 | + type DescribeClusterCommandInput, |
| 4 | + Route53RecoveryControlConfig, |
| 5 | + waitUntilClusterCreated, |
| 6 | +} from "@aws-sdk/client-route53-recovery-control-config"; |
| 7 | +import { type HeadObjectCommandInput, S3, waitUntilObjectExists } from "@aws-sdk/client-s3"; |
| 8 | +import { HttpResponse } from "@smithy/protocol-http"; |
| 9 | +import { Readable } from "node:stream"; |
| 10 | +import { describe, test as it } from "vitest"; |
| 11 | + |
| 12 | +describe("waiters", () => { |
| 13 | + it("should poll until a return condition is met (http status)", async () => { |
| 14 | + const s3 = new S3({ |
| 15 | + credentials: { |
| 16 | + accessKeyId: "INTEG_TEST", |
| 17 | + secretAccessKey: "INTEG_TEST", |
| 18 | + }, |
| 19 | + region: "us-west-2", |
| 20 | + }); |
| 21 | + |
| 22 | + requireRequestsFrom(s3) |
| 23 | + .toMatch( |
| 24 | + { |
| 25 | + hostname: /s3\.us-west-2\.amazonaws\.com/, |
| 26 | + }, |
| 27 | + { |
| 28 | + hostname: /s3\.us-west-2\.amazonaws\.com/, |
| 29 | + } |
| 30 | + ) |
| 31 | + .respondWith( |
| 32 | + new HttpResponse({ |
| 33 | + statusCode: 404, |
| 34 | + headers: {}, |
| 35 | + }), |
| 36 | + new HttpResponse({ |
| 37 | + statusCode: 200, |
| 38 | + headers: {}, |
| 39 | + }) |
| 40 | + ); |
| 41 | + |
| 42 | + const waiterParams: HeadObjectCommandInput = { |
| 43 | + Bucket: "@@@@", |
| 44 | + Key: "####", |
| 45 | + }; |
| 46 | + |
| 47 | + await waitUntilObjectExists({ client: s3, maxDelay: 5, maxWaitTime: 20 }, waiterParams); |
| 48 | + }); |
| 49 | + |
| 50 | + it("should poll until a return condition is met (nested property)", async () => { |
| 51 | + const r53 = new Route53RecoveryControlConfig({ |
| 52 | + credentials: { |
| 53 | + accessKeyId: "INTEG_TEST", |
| 54 | + secretAccessKey: "INTEG_TEST", |
| 55 | + }, |
| 56 | + region: "us-west-2", |
| 57 | + }); |
| 58 | + |
| 59 | + requireRequestsFrom(r53) |
| 60 | + .toMatch( |
| 61 | + { |
| 62 | + hostname: /amazon/, |
| 63 | + }, |
| 64 | + { |
| 65 | + hostname: /amazon/, |
| 66 | + } |
| 67 | + ) |
| 68 | + .respondWith( |
| 69 | + new HttpResponse({ |
| 70 | + statusCode: 200, |
| 71 | + headers: {}, |
| 72 | + body: Readable.from( |
| 73 | + JSON.stringify({ |
| 74 | + Cluster: { |
| 75 | + Status: "PENDING", |
| 76 | + }, |
| 77 | + }) |
| 78 | + ), |
| 79 | + }), |
| 80 | + new HttpResponse({ |
| 81 | + statusCode: 200, |
| 82 | + headers: {}, |
| 83 | + body: Readable.from( |
| 84 | + JSON.stringify({ |
| 85 | + Cluster: { |
| 86 | + Status: "DEPLOYED", |
| 87 | + }, |
| 88 | + }) |
| 89 | + ), |
| 90 | + }) |
| 91 | + ); |
| 92 | + |
| 93 | + const waiterParams: DescribeClusterCommandInput = { |
| 94 | + ClusterArn: "@@@@", |
| 95 | + }; |
| 96 | + |
| 97 | + await waitUntilClusterCreated({ client: r53, maxDelay: 5, maxWaitTime: 20 }, waiterParams); |
| 98 | + }); |
| 99 | +}, 60_000); |
0 commit comments