From 77ef308172786e4c1ef87d3d11debc6fae62cd1e Mon Sep 17 00:00:00 2001 From: Steffen Neubauer Date: Tue, 14 May 2024 16:06:57 +0200 Subject: [PATCH] test(terraform): add assertion for terraform stdout Follow-up on #6037 (This adds a missing test) --- .../kubernetes/kubernetes-type/common.ts | 2 +- core/test/unit/src/commands/workflow.ts | 2 +- plugins/terraform/test/terraform.ts | 26 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/core/test/integ/src/plugins/kubernetes/kubernetes-type/common.ts b/core/test/integ/src/plugins/kubernetes/kubernetes-type/common.ts index ebeda879f1..dcfeac6680 100644 --- a/core/test/integ/src/plugins/kubernetes/kubernetes-type/common.ts +++ b/core/test/integ/src/plugins/kubernetes/kubernetes-type/common.ts @@ -624,7 +624,7 @@ describe("getManifests", () => { expect(manifests[0].spec.replicas).to.eql(3) }) it("should log a warning if patches don't match manifests", async () => { - garden.log.root["entries"] = [] + garden.log.root["entries"].length = 0 const action = cloneDeep(graph.getDeploy("deploy-action")) action["_config"]["spec"]["patchResources"] = [ { diff --git a/core/test/unit/src/commands/workflow.ts b/core/test/unit/src/commands/workflow.ts index 27db6c8d11..fd571b56cf 100644 --- a/core/test/unit/src/commands/workflow.ts +++ b/core/test/unit/src/commands/workflow.ts @@ -85,7 +85,7 @@ describe("RunWorkflowCommand", () => { it("should add workflowStep metadata to log entries provided to steps", async () => { const _garden = await makeTestGardenA(undefined) // Ensure log entries are empty - _garden.log.root["entries"] = [] + _garden.log.root["entries"].length = 0 const _log = _garden.log const _defaultParams = { garden: _garden, diff --git a/plugins/terraform/test/terraform.ts b/plugins/terraform/test/terraform.ts index 0875b9f081..24cfcabbe1 100644 --- a/plugins/terraform/test/terraform.ts +++ b/plugins/terraform/test/terraform.ts @@ -26,6 +26,7 @@ import { resolveAction } from "@garden-io/core/build/src/graph/actions.js" import { RunTask } from "@garden-io/core/build/src/tasks/run.js" import { defaultTerraformVersion } from "../src/cli.js" import { fileURLToPath } from "node:url" +import { resolveMsg } from "@garden-io/core/build/src/logger/log-entry.js" const moduleDirName = dirname(fileURLToPath(import.meta.url)) @@ -39,6 +40,10 @@ for (const terraformVersion of ["0.13.3", defaultTerraformVersion]) { let testFilePath: string async function reset() { + if (garden?.log?.root) { + garden.log.root["entries"].length = 0 + } + if (tfRoot && (await pathExists(testFilePath))) { await remove(testFilePath) } @@ -253,6 +258,13 @@ for (const terraformVersion of ["0.13.3", defaultTerraformVersion]) { it("should apply a stack on init and use configured variables", async () => { await garden.resolveProvider(garden.log, "terraform") + expect( + garden.log.root + .getLogEntries() + .filter((l) => + resolveMsg(l)?.match(/Apply complete\! Resources: [0-9]+ added, [0-9]+ changed, [0-9]+ destroyed/) + ).length + ).to.be.greaterThan(0) const testFileContent = await readFile(testFilePath) expect(testFileContent.toString()).to.equal("default") }) @@ -617,6 +629,13 @@ for (const terraformVersion of ["0.13.3", defaultTerraformVersion]) { context("autoApply=true", () => { it("should apply a stack on init and use configured variables", async () => { await runTestTask(true) + expect( + garden.log.root + .getLogEntries() + .filter((l) => + resolveMsg(l)?.match(/Apply complete\! Resources: [0-9]+ added, [0-9]+ changed, [0-9]+ destroyed/) + ).length + ).to.be.greaterThan(0) const testFileContent = await readFile(testFilePath) expect(testFileContent.toString()).to.equal("default") }) @@ -1055,6 +1074,13 @@ for (const terraformVersion of ["0.13.3", defaultTerraformVersion]) { context("autoApply=true", () => { it("should apply a stack on init and use configured variables", async () => { await runTestTask(true) + expect( + garden.log.root + .getLogEntries() + .filter((l) => + resolveMsg(l)?.match(/Apply complete\! Resources: [0-9]+ added, [0-9]+ changed, [0-9]+ destroyed/) + ).length + ).to.be.greaterThan(0) const testFileContent = await readFile(testFilePath) expect(testFileContent.toString()).to.equal("default") })