Skip to content

Commit

Permalink
chore(test): disable config clearing by default
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
thsig committed Nov 30, 2023
1 parent 6b25e51 commit cbb7acf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/util/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export type TestGardenOpts = Partial<GardenOpts> & {
noTempDir?: boolean
onlySpecifiedPlugins?: boolean
remoteContainerAuth?: boolean
clearConfigsOnScan?: boolean
}

export class TestGarden extends Garden {
Expand All @@ -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)
Expand Down Expand Up @@ -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<SolveParams, "log"> & { log?: Log }) {
return super.processTasks({ ...params, log: params.log || this.log })
}
Expand Down
3 changes: 3 additions & 0 deletions core/test/unit/src/commands/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cbb7acf

Please sign in to comment.