Skip to content

Commit

Permalink
test(terraform): add assertion for terraform stdout (#6040)
Browse files Browse the repository at this point in the history
Follow-up on #6037 (This adds a missing test)
  • Loading branch information
stefreak committed May 14, 2024
1 parent 53cf895 commit 32653f0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"] = [
{
Expand Down
2 changes: 1 addition & 1 deletion core/test/unit/src/commands/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions plugins/terraform/test/terraform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
})
Expand Down Expand Up @@ -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")
})
Expand Down Expand Up @@ -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")
})
Expand Down

0 comments on commit 32653f0

Please sign in to comment.