|
| 1 | +import { getE2eTestResources } from "@aws-sdk/aws-util-test/src"; |
| 2 | +import { beforeAll, describe, expect, test as it } from "vitest"; |
| 3 | + |
| 4 | +import { CloudFormation, paginateListStacks } from "../src/index"; |
| 5 | + |
| 6 | +describe("@aws-sdk/client-cloudformation", () => { |
| 7 | + let client: CloudFormation; |
| 8 | + let region: string; |
| 9 | + |
| 10 | + beforeAll(async () => { |
| 11 | + const e2eTestResourcesEnv = await getE2eTestResources(); |
| 12 | + Object.assign(process.env, e2eTestResourcesEnv); |
| 13 | + |
| 14 | + region = process?.env?.AWS_SMOKE_TEST_REGION as string; |
| 15 | + |
| 16 | + client = new CloudFormation({ region }); |
| 17 | + }); |
| 18 | + |
| 19 | + describe("Describing stacks", () => { |
| 20 | + it("should return stacks list when describing stacks is called", async () => { |
| 21 | + const result = await client.describeStacks({}); |
| 22 | + |
| 23 | + expect(result).toBeDefined(); |
| 24 | + expect(result.Stacks).toBeDefined(); |
| 25 | + expect(Array.isArray(result.Stacks)).toBe(true); |
| 26 | + }); |
| 27 | + }); |
| 28 | + |
| 29 | + describe("Error handling", () => { |
| 30 | + it("should handle ValidationError for invalid stack creation", async () => { |
| 31 | + const templateBody = '{"Resources":{"member":{"Type":"AWS::SQS::Queue"}}}'; |
| 32 | + |
| 33 | + await expect( |
| 34 | + client.createStack({ |
| 35 | + TemplateBody: templateBody, |
| 36 | + StackName: "", // Empty name should cause ValidationError |
| 37 | + }) |
| 38 | + ).rejects.toThrow( |
| 39 | + expect.objectContaining({ |
| 40 | + name: "ValidationError", |
| 41 | + }) |
| 42 | + ); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe("Paginating responses", () => { |
| 47 | + it("should paginate listStacks operation", async () => { |
| 48 | + const paginator = paginateListStacks({ client }, {}); |
| 49 | + |
| 50 | + let pageCount = 0; |
| 51 | + let lastPage; |
| 52 | + |
| 53 | + for await (const page of paginator) { |
| 54 | + pageCount++; |
| 55 | + lastPage = page; |
| 56 | + if (pageCount >= 3) break; // Get at least three pages |
| 57 | + } |
| 58 | + |
| 59 | + expect(pageCount).toBeGreaterThanOrEqual(1); |
| 60 | + expect(lastPage).toBeDefined(); |
| 61 | + }); |
| 62 | + }); |
| 63 | +}); |
0 commit comments