Skip to content

Commit

Permalink
test: add cases for file exclusion
Browse files Browse the repository at this point in the history
and fix two bugs in the original logic
  • Loading branch information
Orzelius committed Jul 7, 2023
1 parent c5bd0b4 commit e4a9dce
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/graph/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export const actionFromConfig = profileAsync(async function actionFromConfig({
const dependencies = dependenciesFromActionConfig(log, config, configsByKey, definition, templateContext)

if (config.exclude?.includes("**/*")) {
if (config.include?.length !== 0) {
if (config.include && config.include.length !== 0) {
throw new ConfigurationError({
message: deline`Action ${config.kind}.${config.name} (defined at ${configPath})
tries to include files but excludes all files via "**/*".
Expand Down
3 changes: 2 additions & 1 deletion core/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ export class GitHandler extends VcsHandler {
if (!exclude) {
exclude = []
}
exclude.push("**/.garden/**/*")
// Make sure action config is not mutated
exclude = [...exclude, "**/.garden/**/*"]

const gitLog = log
.createLog({})
Expand Down
74 changes: 73 additions & 1 deletion core/test/unit/src/actions/action-configs-to-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
DEFAULT_BUILD_TIMEOUT_SEC,
DEFAULT_DEPLOY_TIMEOUT_SEC,
DEFAULT_RUN_TIMEOUT_SEC,
DEFAULT_TEST_TIMEOUT_SEC
DEFAULT_TEST_TIMEOUT_SEC,
} from "../../../../src/constants"

describe("actionConfigsToGraph", () => {
Expand Down Expand Up @@ -769,4 +769,76 @@ describe("actionConfigsToGraph", () => {
}
)
})

describe("file inclusion-exclusion", () => {
const getBaseParams = ({
include,
exclude,
}: {
include?: string[]
exclude?: string[]
}) => ({
garden,
log,
groupConfigs: [],
configs: [
{
kind: <"Build">"Build",
type: <"test">"test",
name: "foo",
timeout: DEFAULT_BUILD_TIMEOUT_SEC,
internal: {
basePath: tmpDir.path,
},
spec: {},

include,
exclude,
},
],
moduleGraph: new ModuleGraph([], {}),
actionModes: {},
linkedSources: {},
})

it("sets include and exclude", async () => {
const graph = await actionConfigsToGraph({
...getBaseParams({
include: ["include-file"],
exclude: ["exclude-file"],
}),
})
const action = graph.getBuild("foo")

expect(action.getConfig().include).to.eql(["include-file"])
expect(action.getConfig().exclude).to.eql(["exclude-file"])
})

it("sets include to [] if all is excluded", async () => {
const graph = await actionConfigsToGraph({
...getBaseParams({
include: undefined,
exclude: ["**/*", "some-thing-else"],
}),
})
const action = graph.getBuild("foo")

expect(action.getConfig().include).to.eql([])
})

it("throws if everything is excluded but an include is attempted", async () => {
await expectError(
() =>
actionConfigsToGraph({
...getBaseParams({
include: ["some-file"],
exclude: ["**/*"],
}),
}),
{
contains: ['tries to include files but excludes all files via "**/*"'],
}
)
})
})
})

0 comments on commit e4a9dce

Please sign in to comment.