-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(k8s): fix multiple command arguments for exec * chore: fix unit test * chore: add integ test for exec command * chore: fix test * chore: keep optional command arg to avoid breaking change * chore: add deprecation warning for positional command argument
- Loading branch information
Showing
6 changed files
with
139 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
core/test/integ/src/plugins/kubernetes/commands/exec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (C) 2018-2023 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
import { expect } from "chai" | ||
import { ExecCommand } from "../../../../../../src/commands/exec.js" | ||
import type { ConfigGraph } from "../../../../../../src/graph/config-graph.js" | ||
import type { ContainerDeployAction } from "../../../../../../src/plugins/container/config.js" | ||
import { DeployTask } from "../../../../../../src/tasks/deploy.js" | ||
import type { TestGarden } from "../../../../../helpers.js" | ||
import { expectError, withDefaultGlobalOpts } from "../../../../../helpers.js" | ||
import { getContainerTestGarden } from "../container/container.js" | ||
import { CommandError } from "../../../../../../src/exceptions.js" | ||
|
||
describe("runExecCommand", () => { | ||
let garden: TestGarden | ||
let cleanup: (() => void) | undefined | ||
let graph: ConfigGraph | ||
|
||
before(async () => { | ||
;({ garden, cleanup } = await getContainerTestGarden("local")) | ||
const action = await resolveDeployAction("simple-service") | ||
const deployTask = new DeployTask({ | ||
garden, | ||
graph, | ||
log: garden.log, | ||
action, | ||
force: true, | ||
forceBuild: false, | ||
}) | ||
await garden.processTasks({ tasks: [deployTask], log: garden.log, throwOnError: true }) | ||
}) | ||
|
||
async function resolveDeployAction(name: string) { | ||
graph = await garden.getConfigGraph({ log: garden.log, emit: false, actionModes: { default: ["deploy." + name] } }) | ||
return garden.resolveAction<ContainerDeployAction>({ action: graph.getDeploy(name), log: garden.log, graph }) | ||
} | ||
|
||
after(async () => { | ||
if (cleanup) { | ||
cleanup() | ||
} | ||
}) | ||
|
||
it("should exec a command in a running service using the -- separator", async () => { | ||
const execCommand = new ExecCommand() | ||
const args = { deploy: "simple-service", command: "" } | ||
args["--"] = ["echo", "ok, lots of text"] | ||
|
||
const { result, errors } = await execCommand.action({ | ||
garden, | ||
log: garden.log, | ||
args, | ||
opts: withDefaultGlobalOpts({ | ||
interactive: false, | ||
target: "", | ||
}), | ||
}) | ||
|
||
if (errors) { | ||
throw errors[0] | ||
} | ||
expect(result?.output).to.equal("ok, lots of text") | ||
}) | ||
|
||
it("should exec a command in a running service without the -- separator", async () => { | ||
const execCommand = new ExecCommand() | ||
const args = { deploy: "simple-service", command: "echo hello" } | ||
|
||
const { result, errors } = await execCommand.action({ | ||
garden, | ||
log: garden.log, | ||
args, | ||
opts: withDefaultGlobalOpts({ | ||
interactive: false, | ||
target: "", | ||
}), | ||
}) | ||
|
||
if (errors) { | ||
throw errors[0] | ||
} | ||
expect(result?.output).to.equal("hello") | ||
}) | ||
|
||
it("should throw if no command was specified", async () => { | ||
const execCommand = new ExecCommand() | ||
const args = { deploy: "simple-service", command: "" } | ||
await expectError( | ||
() => | ||
execCommand.action({ | ||
garden, | ||
log: garden.log, | ||
args, | ||
opts: withDefaultGlobalOpts({ | ||
interactive: false, | ||
target: "", | ||
}), | ||
}), | ||
(err) => | ||
expect(err).to.be.instanceOf(CommandError).with.property("message", "No command specified. Nothing to execute.") | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters