From eadbbb9bcf81eac61ef159f3a0ef2dc548db4c1e Mon Sep 17 00:00:00 2001 From: Ansgar Mertens Date: Wed, 22 Nov 2023 14:09:18 +0100 Subject: [PATCH] chore(tests): move terraform validation code into new TestDriver.validate() method --- test/test-helper.ts | 12 ++++++++++++ test/typescript/iterators/test.ts | 5 ++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/test/test-helper.ts b/test/test-helper.ts index 2f7c44dfb2..4674ef1c15 100644 --- a/test/test-helper.ts +++ b/test/test-helper.ts @@ -289,6 +289,18 @@ export class TestDriver { return child; }; + /** + * runs terraform init and terraform validate in the output directory for the given stack name + * @param stack the name of the stack to validate + * @returns the stdout of terraform validate + */ + async validate(stack: string) { + const cwd = path.join(this.workingDirectory, "cdktf.out", "stacks", stack); + await this.exec("terraform", ["init"], cwd); + const res = await this.exec("terraform", ["validate"], cwd); + return res.stdout; + } + setupTypescriptProject = async (options?: { init?: { additionalOptions?: string }; }) => { diff --git a/test/typescript/iterators/test.ts b/test/typescript/iterators/test.ts index 5ebea485ac..83c080d5ee 100644 --- a/test/typescript/iterators/test.ts +++ b/test/typescript/iterators/test.ts @@ -69,9 +69,8 @@ describe("iterators integration test", () => { }); test("non-synth stack is valid Terraform", async () => { - await driver.exec("terraform", ["init"]); - const res = await driver.exec("terraform", ["validate"]); - expect(res.stdout).toContain("Success! The configuration is valid."); + const out = await driver.validate("test-iterators-synth-only"); + expect(out).toContain("Success! The configuration is valid."); }); test("apply produces the correct result for outputs", async () => {