Skip to content

Commit

Permalink
chore(tests): move terraform validation code into new TestDriver.vali…
Browse files Browse the repository at this point in the history
…date() method
  • Loading branch information
ansgarm committed Nov 22, 2023
1 parent f7bd6d8 commit eadbbb9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 12 additions & 0 deletions test/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}) => {
Expand Down
5 changes: 2 additions & 3 deletions test/typescript/iterators/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit eadbbb9

Please sign in to comment.