From 6f4b9b6705cbae773ceffbb04f8f0f917ba36ff4 Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Thu, 30 Nov 2023 18:35:07 +0100 Subject: [PATCH] chore(test): disable config clearing by default The call to `this.clearConfig()` in `Garden#scanAndAddConfigs` had started breaking certain test cases that manually set action configs before calling `garden.getConfigGraph` (which would scan and add configs, thus discarding the manually set configs). While it's not great that we're adding more tweaks to the `TestGarden` class, we're almost never interested in explicitly testing the post-edit config reloading (outside of tests that test interactive / dev command funcftionality). --- core/src/garden.ts | 2 +- core/src/util/testing.ts | 10 ++++++++++ core/test/unit/src/commands/base.ts | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/src/garden.ts b/core/src/garden.ts index 2f36155e00..686427a1df 100644 --- a/core/src/garden.ts +++ b/core/src/garden.ts @@ -1287,7 +1287,7 @@ export class Garden { * We need to clear before rescanning to make sure old/outdated configs are cleared away, and to avoid duplicate * key errors when adding the newly scanned ones (and those generated from newly scanned config templates). */ - private clearConfigs() { + protected clearConfigs() { for (const kind of Object.getOwnPropertyNames(this.actionConfigs)) { clearObject(this.actionConfigs[kind]) } diff --git a/core/src/util/testing.ts b/core/src/util/testing.ts index 50d33b35b5..7e3d7aa419 100644 --- a/core/src/util/testing.ts +++ b/core/src/util/testing.ts @@ -165,6 +165,7 @@ export type TestGardenOpts = Partial & { noTempDir?: boolean onlySpecifiedPlugins?: boolean remoteContainerAuth?: boolean + clearConfigsOnScan?: boolean } export class TestGarden extends Garden { @@ -179,6 +180,7 @@ export class TestGarden extends Garden { public declare variables: DeepPrimitiveMap private repoRoot!: string public cacheKey!: string + public clearConfigsOnScan = false constructor(params: GardenParams) { super(params) @@ -228,6 +230,14 @@ export class TestGarden extends Garden { return garden } + protected override clearConfigs() { + if (this.clearConfigsOnScan) { + super.clearConfigs() + } else { + // No-op: We need to disable this method, because it breaks test cases that manually set configs. + } + } + override async processTasks(params: Omit & { log?: Log }) { return super.processTasks({ ...params, log: params.log || this.log }) } diff --git a/core/test/unit/src/commands/base.ts b/core/test/unit/src/commands/base.ts index af07ccb77e..4c8625b4b3 100644 --- a/core/test/unit/src/commands/base.ts +++ b/core/test/unit/src/commands/base.ts @@ -226,6 +226,9 @@ describe("Command", () => { it("passes on changed configs and templates to the parent and subsequent child instances", async () => { const garden = await makeTestGarden(projectRoot) + // Here, we're testing the config clearing logic, so we turn this behavior on (which is off by default for + // TestGarden instances). + garden.clearConfigsOnScan = true // `makeTestGarden` does some trickery to copy the project root into a temp directory and work from there // (which is nice, since it avoids the need for cleanup). // Therefore, we need to make our find & replace substitutions inside the temp dir here.