From 24446c1345382a52608a2a697b647ec6b9d1e19b Mon Sep 17 00:00:00 2001 From: Walther Date: Wed, 31 May 2023 18:48:04 +0300 Subject: [PATCH] chore: return the separate getRootLogMessages and getLogMessages other unrelated tests were depending on the specific behavior. we can always come back to refactor further. --- core/src/util/testing.ts | 12 ++++++++++-- plugins/terraform/test/terraform.ts | 6 +++--- sdk/testing.ts | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/src/util/testing.ts b/core/src/util/testing.ts index 7c0f7e14052..f2fd401beb3 100644 --- a/core/src/util/testing.ts +++ b/core/src/util/testing.ts @@ -46,16 +46,24 @@ export interface EventLogEntry { } /** - * Retrieves all the log entries via the root log and returns a list of all the messages, + * Retrieves the log entries from the given log context and returns a list of all the messages, * stripped of ANSI characters. Useful to check if a particular message was logged. */ export function getLogMessages(log: Log, filter?: (log: LogEntry) => boolean) { return log - .getAllLogEntries() + .getLogEntries() .filter((entry) => (filter ? filter(entry) : true)) .map((entry) => stripAnsi(entry.msg || "")) } +/** + * Retrieves all the entries from the root log and returns a list of all the messages, + * stripped of ANSI characters. Useful to check if a particular message was logged. + */ +export function getRootLogMessages(log: Log, filter?: (log: LogEntry) => boolean) { + return log.getAllLogEntries().filter((entry) => (filter ? filter(entry) : true)) +} + type PartialActionConfig = Partial & { kind: ActionKind; type: string; name: string } type PartialModuleConfig = Partial & { name: string; path: string } diff --git a/plugins/terraform/test/terraform.ts b/plugins/terraform/test/terraform.ts index ae6649445c8..0d04a0cb6b8 100644 --- a/plugins/terraform/test/terraform.ts +++ b/plugins/terraform/test/terraform.ts @@ -11,7 +11,7 @@ import { join } from "path" import { expect } from "chai" import { pathExists, readFile, remove } from "fs-extra" -import { getLogMessages, makeTestGarden, TestGarden } from "@garden-io/sdk/testing" +import { getRootLogMessages, makeTestGarden, TestGarden } from "@garden-io/sdk/testing" import { findByName } from "@garden-io/core/build/src/util/util" import { getTerraformCommands } from "../commands" import { ConfigGraph, LogLevel } from "@garden-io/sdk/types" @@ -64,7 +64,7 @@ for (const terraformVersion of ["0.13.3", defaultTerraformVersion]) { it("should warn if stack is not up-to-date", async () => { const provider = await garden.resolveProvider(garden.log, "terraform") - const messages = getLogMessages(garden.log, (e) => e.level === LogLevel.warn) + const messages = getRootLogMessages(garden.log, (e) => e.level === LogLevel.warn) expect(messages).to.include( "Terraform stack is not up-to-date and autoApply is not enabled. Please run garden plugins terraform apply-root to make sure the stack is in the intended state." ) @@ -507,7 +507,7 @@ for (const terraformVersion of ["0.13.3", defaultTerraformVersion]) { context("autoApply=false", () => { it("should warn if the stack is out of date", async () => { await deployStack(false) - const messages = getLogMessages(garden.log, (e) => e.level === LogLevel.warn) + const messages = getRootLogMessages(garden.log, (e) => e.level === LogLevel.warn) expect(messages).to.include( "Stack is out-of-date but autoApply is set to false, so it will not be applied automatically. If any newly added stack outputs are referenced via ${runtime.services.tf.outputs.*} template strings and are missing, you may see errors when resolving them." ) diff --git a/sdk/testing.ts b/sdk/testing.ts index e20e28eecde..29c052a7937 100644 --- a/sdk/testing.ts +++ b/sdk/testing.ts @@ -10,7 +10,7 @@ import { TestGarden, TestGardenOpts } from "@garden-io/core/build/src/util/testi import { uuidv4 } from "@garden-io/core/build/src/util/random" import { LogLevel, RootLogger } from "@garden-io/core/build/src/logger/logger" -export { TestGarden, getLogMessages } from "@garden-io/core/build/src/util/testing" +export { TestGarden, getLogMessages, getRootLogMessages } from "@garden-io/core/build/src/util/testing" export { expectError } from "@garden-io/core/build/src/util/testing" export { makeTempDir } from "@garden-io/core/build/src/util/fs"