diff --git a/docs/reference/commands.md b/docs/reference/commands.md index c418d08330..70fc3c23f8 100644 --- a/docs/reference/commands.md +++ b/docs/reference/commands.md @@ -74,65 +74,20 @@ Note: Currently only supports HTTP/HTTPS endpoints. | -------- | -------- | ----------- | | `serviceAndPath` | Yes | The name of the service(s) to call followed by the endpoint path (e.g. my-container/somepath). -### garden config get +### garden delete config -Get a configuration variable from the environment.. +Delete a configuration variable from the environment.. Returns with an error if the provided key could not be found in the configuration. Examples: - garden get somekey - garden get some.nested.key + garden delete config somekey + garden del config some.nested.key ##### Usage - garden config get - -##### Arguments - -| Argument | Required | Description | -| -------- | -------- | ----------- | - | `key` | Yes | The key of the configuration variable. Separate with dots to get a nested key (e.g. key.nested). - -### garden config set - -Set a configuration variable in the environment.. - -These configuration values can be referenced in module templates, for example as environment variables. - -_Note: The value is always stored as a string._ - -Examples: - - garden set somekey myvalue - garden set some.nested.key myvalue - -##### Usage - - garden config set - -##### Arguments - -| Argument | Required | Description | -| -------- | -------- | ----------- | - | `key` | Yes | The key of the configuration variable. Separate with dots to get a nested key (e.g. key.nested). - | `value` | Yes | The value of the configuration variable. - -### garden config delete - -Delete a configuration variable from the Garden environment.. - -Returns with an error if the provided key could not be found in the configuration. - -Examples: - - garden delete somekey - garden delete some.nested.key - -##### Usage - - garden config delete + garden delete config ##### Arguments @@ -196,43 +151,58 @@ Starts the garden development console.. garden dev -### garden environment configure +### garden get config -Configures your environment.. +Get a configuration variable from the environment.. -Generally, environments are configured automatically as part of other commands that you run. -However, this command is useful if you want to make sure the environment is ready before running -another command, or if you need to force a reconfiguration using the --force flag. +Returns with an error if the provided key could not be found in the configuration. Examples: - garden env configure - garden env configure --force + garden get config somekey + garden get config some.nested.key ##### Usage - garden environment configure [options] + garden get config -##### Options +##### Arguments -| Argument | Alias | Type | Description | -| -------- | ----- | ---- | ----------- | - | `--force` | | boolean | Force reconfiguration of environment, ignoring the environment status check. +| Argument | Required | Description | +| -------- | -------- | ----------- | + | `key` | Yes | The key of the configuration variable. Separate with dots to get a nested key (e.g. key.nested). -### garden environment destroy +### garden get status -Destroy an environment.. +Outputs the status of your environment.. -Generally not as dramatic as it sounds :) This will trigger providers clear up any deployments in a -Garden environment and reset it. When you then run `garden env configure` or any deployment command, -the environment will be reconfigured. -This can be useful if you find the environment to be in an inconsistent state, or need/want to free up -resources. +##### Usage + + garden get status + +### garden init environment + +Initializes your environment.. + +Generally, environments are initialized automatically as part of other commands that you run. +However, this command is useful if you want to make sure the environment is ready before running +another command, or if you need to force a re-initialization using the --force flag. + +Examples: + + garden init env + garden init env --force ##### Usage - garden environment destroy + garden init environment [options] + +##### Options + +| Argument | Alias | Type | Description | +| -------- | ----- | ---- | ----------- | + | `--force` | | boolean | Force initalization of environment, ignoring the environment status check. ### garden login @@ -413,14 +383,29 @@ Scans your project and outputs an overview of all modules.. garden scan -### garden status +### garden set config -Outputs the status of your environment.. +Set a configuration variable in the environment.. +These configuration values can be referenced in module templates, for example as environment variables. + +_Note: The value is always stored as a string._ + +Examples: + + garden set config somekey myvalue + garden set config some.nested.key myvalue ##### Usage - garden status + garden set config + +##### Arguments + +| Argument | Required | Description | +| -------- | -------- | ----------- | + | `key` | Yes | The key of the configuration variable. Separate with dots to get a nested key (e.g. key.nested). + | `value` | Yes | The value of the configuration variable. ### garden test diff --git a/src/commands/commands.ts b/src/commands/commands.ts index d17b7384ba..117c1342ef 100644 --- a/src/commands/commands.ts +++ b/src/commands/commands.ts @@ -9,34 +9,36 @@ import { Command } from "./base" import { BuildCommand } from "./build" import { CallCommand } from "./call" -import { ConfigCommand } from "./config/config" +import { InitCommand } from "./init" +import { DeleteCommand } from "./delete" import { DeployCommand } from "./deploy" import { DevCommand } from "./dev" -import { EnvironmentCommand } from "./environment/environment" +import { GetCommand } from "./get" import { LoginCommand } from "./login" import { LogoutCommand } from "./logout" import { LogsCommand } from "./logs" import { PushCommand } from "./push" import { RunCommand } from "./run/run" import { ScanCommand } from "./scan" -import { StatusCommand } from "./status" +import { SetCommand } from "./set" import { TestCommand } from "./test" import { ValidateCommand } from "./validate" export const coreCommands: Command[] = [ new BuildCommand(), new CallCommand(), - new ConfigCommand(), + new DeleteCommand(), new DeployCommand(), new DevCommand(), - new EnvironmentCommand(), + new GetCommand(), + new InitCommand(), new LoginCommand(), new LogoutCommand(), new LogsCommand(), new PushCommand(), new RunCommand(), new ScanCommand(), - new StatusCommand(), + new SetCommand(), new TestCommand(), new ValidateCommand(), ] diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts deleted file mode 100644 index ada83cfd71..0000000000 --- a/src/commands/config/config.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2018 Garden Technologies, Inc. - * - * 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 { Command } from "../base" -import { ConfigGetCommand } from "./get" -import { ConfigDeleteCommand } from "./delete" -import { ConfigSetCommand } from "./set" - -export class ConfigCommand extends Command { - name = "config" - alias = "c" - help = "Manage configuration variables in your environment" - - subCommands = [ - ConfigGetCommand, - ConfigSetCommand, - ConfigDeleteCommand, - ] - - async action() { return {} } -} diff --git a/src/commands/config/delete.ts b/src/commands/config/delete.ts deleted file mode 100644 index 96a9a1e794..0000000000 --- a/src/commands/config/delete.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2018 Garden Technologies, Inc. - * - * 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 { PluginContext } from "../../plugin-context" -import { DeleteConfigResult } from "../../types/plugin/outputs" -import { - Command, - CommandResult, - ParameterValues, - StringParameter, -} from "../base" -import { NotFoundError } from "../../exceptions" -import dedent = require("dedent") - -export const configDeleteArgs = { - key: new StringParameter({ - help: "The key of the configuration variable. Separate with dots to get a nested key (e.g. key.nested).", - required: true, - }), -} - -export type DeleteArgs = ParameterValues - -// TODO: add --all option to remove all configs - -export class ConfigDeleteCommand extends Command { - name = "delete" - alias = "del" - help = "Delete a configuration variable from the Garden environment." - - description = dedent` - Returns with an error if the provided key could not be found in the configuration. - - Examples: - - garden delete somekey - garden delete some.nested.key - ` - - arguments = configDeleteArgs - - async action(ctx: PluginContext, args: DeleteArgs): Promise> { - const key = args.key.split(".") - const result = await ctx.deleteConfig({ key }) - - if (result.found) { - ctx.log.info(`Deleted config key ${args.key}`) - } else { - throw new NotFoundError(`Could not find config key ${args.key}`, { key }) - } - - return { result } - } -} diff --git a/src/commands/config/get.ts b/src/commands/config/get.ts deleted file mode 100644 index ee2b95a5d6..0000000000 --- a/src/commands/config/get.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2018 Garden Technologies, Inc. - * - * 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 { NotFoundError } from "../../exceptions" -import { PluginContext } from "../../plugin-context" -import { - Command, - CommandResult, - ParameterValues, - StringParameter, -} from "../base" -import dedent = require("dedent") - -export const configGetArgs = { - key: new StringParameter({ - help: "The key of the configuration variable. Separate with dots to get a nested key (e.g. key.nested).", - required: true, - }), -} - -export type GetArgs = ParameterValues - -// TODO: allow omitting key to return all configs - -export class ConfigGetCommand extends Command { - name = "get" - help = "Get a configuration variable from the environment." - - description = dedent` - Returns with an error if the provided key could not be found in the configuration. - - Examples: - - garden get somekey - garden get some.nested.key - ` - - arguments = configGetArgs - - async action(ctx: PluginContext, args: GetArgs): Promise { - const key = args.key.split(".") - const { value } = await ctx.getConfig({ key }) - - if (value === null || value === undefined) { - throw new NotFoundError(`Could not find config key ${args.key}`, { key }) - } - - ctx.log.info(value) - - return { [args.key]: value } - } -} diff --git a/src/commands/delete.ts b/src/commands/delete.ts new file mode 100644 index 0000000000..ff2af09d42 --- /dev/null +++ b/src/commands/delete.ts @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2018 Garden Technologies, Inc. + * + * 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 { PluginContext } from "../plugin-context" +import { + DeleteConfigResult, + EnvironmentStatusMap, +} from "../types/plugin/outputs" +import { + Command, + CommandResult, + ParameterValues, + StringParameter, +} from "./base" +import { NotFoundError } from "../exceptions" +import dedent = require("dedent") + +export class DeleteCommand extends Command { + name = "delete" + alias = "del" + help = "Delete configuration or objects." + + subCommands = [ + DeleteConfigCommand, + ] + + async action() { return {} } +} + +export const deleteConfigArgs = { + key: new StringParameter({ + help: "The key of the configuration variable. Separate with dots to get a nested key (e.g. key.nested).", + required: true, + }), +} + +export type DeleteArgs = ParameterValues + +// TODO: add --all option to remove all configs + +export class DeleteConfigCommand extends Command { + name = "config" + help = "Delete a configuration variable from the environment." + + description = dedent` + Returns with an error if the provided key could not be found in the configuration. + + Examples: + + garden delete config somekey + garden del config some.nested.key + ` + + arguments = deleteConfigArgs + + async action(ctx: PluginContext, args: DeleteArgs): Promise> { + const key = args.key.split(".") + const result = await ctx.deleteConfig({ key }) + + if (result.found) { + ctx.log.info(`Deleted config key ${args.key}`) + } else { + throw new NotFoundError(`Could not find config key ${args.key}`, { key }) + } + + return { result } + } +} + +export class DeleteEnvironmentCommand extends Command { + name = "environment" + alias = "env" + help = "Deletes a running environment." + + description = dedent` + This will trigger providers to clear up any deployments in a Garden environment and reset it. + When you then run \`garden configure env\` or any deployment command, the environment will be reconfigured. + + This can be useful if you find the environment to be in an inconsistent state, or need/want to free up + resources. + ` + + async action(ctx: PluginContext): Promise> { + const { name } = ctx.getEnvironment() + ctx.log.header({ emoji: "skull_and_crossbones", command: `Deleting ${name} environment` }) + + const result = await ctx.destroyEnvironment({}) + + ctx.log.finish() + + return { result } + } +} diff --git a/src/commands/environment/configure.ts b/src/commands/environment/configure.ts deleted file mode 100644 index 6434434987..0000000000 --- a/src/commands/environment/configure.ts +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2018 Garden Technologies, Inc. - * - * 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 { PluginContext } from "../../plugin-context" -import { EnvironmentStatusMap } from "../../types/plugin/outputs" -import { - BooleanParameter, - Command, - CommandResult, - ParameterValues, -} from "../base" -import dedent = require("dedent") - -export const options = { - force: new BooleanParameter({ help: "Force reconfiguration of environment, ignoring the environment status check." }), -} - -export type Opts = ParameterValues - -export class EnvironmentConfigureCommand extends Command { - name = "configure" - alias = "config" - help = "Configures your environment." - - description = dedent` - Generally, environments are configured automatically as part of other commands that you run. - However, this command is useful if you want to make sure the environment is ready before running - another command, or if you need to force a reconfiguration using the --force flag. - - Examples: - - garden env configure - garden env configure --force - ` - - options = options - - async action(ctx: PluginContext, _args, opts: Opts): Promise> { - const { name } = ctx.getEnvironment() - ctx.log.header({ emoji: "gear", command: `Configuring ${name} environment` }) - - const result = await ctx.configureEnvironment({ force: opts.force }) - - ctx.log.info("") - ctx.log.header({ emoji: "heavy_check_mark", command: `Done!` }) - - return { result } - } -} diff --git a/src/commands/environment/destroy.ts b/src/commands/environment/destroy.ts deleted file mode 100644 index f393960c3d..0000000000 --- a/src/commands/environment/destroy.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2018 Garden Technologies, Inc. - * - * 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 { PluginContext } from "../../plugin-context" - -import { - Command, - CommandResult, -} from "../base" -import { EnvironmentStatusMap } from "../../types/plugin/outputs" -import dedent = require("dedent") - -export class EnvironmentDestroyCommand extends Command { - name = "destroy" - alias = "d" - help = "Destroy an environment." - - description = dedent` - Generally not as dramatic as it sounds :) This will trigger providers clear up any deployments in a - Garden environment and reset it. When you then run \`garden env configure\` or any deployment command, - the environment will be reconfigured. - - This can be useful if you find the environment to be in an inconsistent state, or need/want to free up - resources. - ` - - async action(ctx: PluginContext): Promise> { - const { name } = ctx.getEnvironment() - ctx.log.header({ emoji: "skull_and_crossbones", command: `Destroying ${name} environment` }) - - const result = await ctx.destroyEnvironment({}) - - ctx.log.finish() - - return { result } - } - -} diff --git a/src/commands/environment/environment.ts b/src/commands/environment/environment.ts deleted file mode 100644 index f81c1c4086..0000000000 --- a/src/commands/environment/environment.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2018 Garden Technologies, Inc. - * - * 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 { Command } from "../base" -import { EnvironmentConfigureCommand } from "./configure" -import { EnvironmentDestroyCommand } from "./destroy" - -export class EnvironmentCommand extends Command { - name = "environment" - alias = "env" - help = "Manage your runtime environment(s)" - - subCommands = [ - EnvironmentConfigureCommand, - EnvironmentDestroyCommand, - ] - - async action() { return {} } -} diff --git a/src/commands/get.ts b/src/commands/get.ts new file mode 100644 index 0000000000..34c2ef2f62 --- /dev/null +++ b/src/commands/get.ts @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2018 Garden Technologies, Inc. + * + * 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 * as yaml from "js-yaml" +import { NotFoundError } from "../exceptions" +import { + ContextStatus, + PluginContext, +} from "../plugin-context" +import { highlightYaml } from "../util/util" +import { + Command, + CommandResult, + ParameterValues, + StringParameter, +} from "./base" +import dedent = require("dedent") + +export class GetCommand extends Command { + name = "get" + help = "Retrieve and output data and objects, e.g. configuration variables, status info etc." + + subCommands = [ + GetConfigCommand, + GetStatusCommand, + ] + + async action() { return {} } +} + +export const getConfigArgs = { + key: new StringParameter({ + help: "The key of the configuration variable. Separate with dots to get a nested key (e.g. key.nested).", + required: true, + }), +} + +export type GetArgs = ParameterValues + +// TODO: allow omitting key to return all configs + +export class GetConfigCommand extends Command { + name = "config" + help = "Get a configuration variable from the environment." + + description = dedent` + Returns with an error if the provided key could not be found in the configuration. + + Examples: + + garden get config somekey + garden get config some.nested.key + ` + + arguments = getConfigArgs + + async action(ctx: PluginContext, args: GetArgs): Promise { + const key = args.key.split(".") + const { value } = await ctx.getConfig({ key }) + + if (value === null || value === undefined) { + throw new NotFoundError(`Could not find config key ${args.key}`, { key }) + } + + ctx.log.info(value) + + return { [args.key]: value } + } +} + +export class GetStatusCommand extends Command { + name = "status" + help = "Outputs the status of your environment." + + async action(ctx: PluginContext): Promise> { + const status = await ctx.getStatus() + const yamlStatus = yaml.safeDump(status, { noRefs: true, skipInvalid: true }) + + // TODO: do a nicer print of this by default and add --yaml/--json options (maybe globally) for exporting + ctx.log.info(highlightYaml(yamlStatus)) + + return { result: status } + } +} diff --git a/src/commands/init.ts b/src/commands/init.ts new file mode 100644 index 0000000000..333df9d2d6 --- /dev/null +++ b/src/commands/init.ts @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2018 Garden Technologies, Inc. + * + * 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 { PluginContext } from "../plugin-context" +import { EnvironmentStatusMap } from "../types/plugin/outputs" +import { + BooleanParameter, + Command, + CommandResult, + ParameterValues, +} from "./base" +import dedent = require("dedent") + +export class InitCommand extends Command { + name = "init" + help = "Initialize environment or other runtime components." + + subCommands = [ + InitEnvironmentCommand, + ] + + async action() { return {} } +} + +export const initEnvOptions = { + force: new BooleanParameter({ help: "Force initalization of environment, ignoring the environment status check." }), +} + +export type InitEnvOpts = ParameterValues + +export class InitEnvironmentCommand extends Command { + name = "environment" + alias = "env" + help = "Initializes your environment." + + description = dedent` + Generally, environments are initialized automatically as part of other commands that you run. + However, this command is useful if you want to make sure the environment is ready before running + another command, or if you need to force a re-initialization using the --force flag. + + Examples: + + garden init env + garden init env --force + ` + + options = initEnvOptions + + async action(ctx: PluginContext, _args, opts: InitEnvOpts): Promise> { + const { name } = ctx.getEnvironment() + ctx.log.header({ emoji: "gear", command: `Initializing ${name} environment` }) + + const result = await ctx.configureEnvironment({ force: opts.force }) + + ctx.log.info("") + ctx.log.header({ emoji: "heavy_check_mark", command: `Done!` }) + + return { result } + } +} diff --git a/src/commands/config/set.ts b/src/commands/set.ts similarity index 68% rename from src/commands/config/set.ts rename to src/commands/set.ts index e2c01ee46d..3f0312dae5 100644 --- a/src/commands/config/set.ts +++ b/src/commands/set.ts @@ -6,17 +6,28 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { PluginContext } from "../../plugin-context" -import { SetConfigResult } from "../../types/plugin/outputs" +import { PluginContext } from "../plugin-context" +import { SetConfigResult } from "../types/plugin/outputs" import { Command, CommandResult, ParameterValues, StringParameter, -} from "../base" +} from "./base" import dedent = require("dedent") -export const configSetArgs = { +export class SetCommand extends Command { + name = "set" + help = "Set or modify data, e.g. configuration variables." + + subCommands = [ + SetConfigCommand, + ] + + async action() { return {} } +} + +export const setConnfigArgs = { // TODO: specify and validate config key schema here key: new StringParameter({ help: "The key of the configuration variable. Separate with dots to get a nested key (e.g. key.nested).", @@ -28,12 +39,12 @@ export const configSetArgs = { }), } -export type SetArgs = ParameterValues +export type SetArgs = ParameterValues // TODO: allow reading key/value pairs from a file -export class ConfigSetCommand extends Command { - name = "set" +export class SetConfigCommand extends Command { + name = "config" help = "Set a configuration variable in the environment." description = dedent` @@ -43,11 +54,11 @@ export class ConfigSetCommand extends Command { Examples: - garden set somekey myvalue - garden set some.nested.key myvalue + garden set config somekey myvalue + garden set config some.nested.key myvalue ` - arguments = configSetArgs + arguments = setConnfigArgs async action(ctx: PluginContext, args: SetArgs): Promise> { const key = args.key.split(".") diff --git a/src/commands/status.ts b/src/commands/status.ts deleted file mode 100644 index 1e89071a24..0000000000 --- a/src/commands/status.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2018 Garden Technologies, Inc. - * - * 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 * as yaml from "js-yaml" -import { - ContextStatus, - PluginContext, -} from "../plugin-context" -import { - Command, - CommandResult, -} from "./base" -import { highlightYaml } from "../util/util" - -export class StatusCommand extends Command { - name = "status" - alias = "s" - help = "Outputs the status of your environment." - - async action(ctx: PluginContext): Promise> { - const status = await ctx.getStatus() - const yamlStatus = yaml.safeDump(status, { noRefs: true, skipInvalid: true }) - - // TODO: do a nicer print of this by default and add --yaml/--json options (maybe globally) for exporting - ctx.log.info(highlightYaml(yamlStatus)) - - return { result: status } - } -} diff --git a/test/src/commands/config/delete.ts b/test/src/commands/config/delete.ts deleted file mode 100644 index 597ec8037c..0000000000 --- a/test/src/commands/config/delete.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { ConfigDeleteCommand } from "../../../../src/commands/config/delete" -import { expectError, makeTestContextA } from "../../../helpers" -import { expect } from "chai" - -describe("ConfigDeleteCommand", () => { - it("should delete a config variable", async () => { - const ctx = await makeTestContextA() - const command = new ConfigDeleteCommand() - - const key = ["project", "mykey"] - const value = "myvalue" - - await ctx.setConfig({ key, value }) - - await command.action(ctx, { key: "project.mykey" }) - - expect(await ctx.getConfig({ key })).to.eql({ value: null }) - }) - - it("should throw on invalid key", async () => { - const ctx = await makeTestContextA() - const command = new ConfigDeleteCommand() - - await expectError( - async () => await command.action(ctx, { key: "bla.mykey" }), - "parameter", - ) - }) - - it("should throw on missing key", async () => { - const ctx = await makeTestContextA() - const command = new ConfigDeleteCommand() - - await expectError( - async () => await command.action(ctx, { key: "project.mykey" }), - "not-found", - ) - }) -}) diff --git a/test/src/commands/delete.ts b/test/src/commands/delete.ts new file mode 100644 index 0000000000..06177ce641 --- /dev/null +++ b/test/src/commands/delete.ts @@ -0,0 +1,84 @@ +import { join } from "path" +import { + DeleteConfigCommand, + DeleteEnvironmentCommand, +} from "../../../src/commands/delete" +import { Garden } from "../../../src/garden" +import { EnvironmentStatus } from "../../../src/types/plugin/outputs" +import { PluginFactory } from "../../../src/types/plugin/plugin" +import { expectError, makeTestContextA } from "../../helpers" +import { expect } from "chai" + +describe("DeleteConfigCommand", () => { + it("should delete a config variable", async () => { + const ctx = await makeTestContextA() + const command = new DeleteConfigCommand() + + const key = ["project", "mykey"] + const value = "myvalue" + + await ctx.setConfig({ key, value }) + + await command.action(ctx, { key: "project.mykey" }) + + expect(await ctx.getConfig({ key })).to.eql({ value: null }) + }) + + it("should throw on invalid key", async () => { + const ctx = await makeTestContextA() + const command = new DeleteConfigCommand() + + await expectError( + async () => await command.action(ctx, { key: "bla.mykey" }), + "parameter", + ) + }) + + it("should throw on missing key", async () => { + const ctx = await makeTestContextA() + const command = new DeleteConfigCommand() + + await expectError( + async () => await command.action(ctx, { key: "project.mykey" }), + "not-found", + ) + }) +}) + +describe("DeleteEnvironmentCommand", () => { + const testProvider: PluginFactory = () => { + const name = "test-plugin" + + const testEnvStatuses: { [key: string]: EnvironmentStatus } = {} + + const destroyEnvironment = async () => { + testEnvStatuses[name] = { configured: false } + return {} + } + + const getEnvironmentStatus = async () => { + return testEnvStatuses[name] + } + + return { + actions: { + destroyEnvironment, + getEnvironmentStatus, + }, + } + } + + testProvider.pluginName = "test-plugin" + + const projectRootB = join(__dirname, "..", "..", "data", "test-project-b") + const command = new DeleteEnvironmentCommand() + + it("should destroy environment", async () => { + const garden = await Garden.factory(projectRootB, { plugins: [testProvider] }) + + const { result } = await command.action(garden.pluginContext) + + expect(result!["test-plugin"]["configured"]).to.be.false + }) + +}) diff --git a/test/src/commands/environment/destroy.ts b/test/src/commands/environment/destroy.ts deleted file mode 100644 index 76902ab792..0000000000 --- a/test/src/commands/environment/destroy.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { expect } from "chai" -import { join } from "path" - -import { - PluginFactory, -} from "../../../../src/types/plugin/plugin" -import { EnvironmentDestroyCommand } from "../../../../src/commands/environment/destroy" -import { Garden } from "../../../../src/garden" -import { EnvironmentStatus } from "../../../../src/types/plugin/outputs" - -const testProvider: PluginFactory = () => { - const name = "test-plugin" - - const testEnvStatuses: { [key: string]: EnvironmentStatus } = {} - - const destroyEnvironment = async () => { - testEnvStatuses[name] = { configured: false } - return {} - } - - const getEnvironmentStatus = async () => { - return testEnvStatuses[name] - } - - return { - actions: { - destroyEnvironment, - getEnvironmentStatus, - }, - } -} - -testProvider.pluginName = "test-plugin" - -describe("EnvironmentDestroyCommand", () => { - const projectRootB = join(__dirname, "..", "..", "..", "data", "test-project-b") - const command = new EnvironmentDestroyCommand() - - it("should destroy environment", async () => { - const garden = await Garden.factory(projectRootB, { plugins: [testProvider] }) - - const { result } = await command.action(garden.pluginContext) - - expect(result!["test-plugin"]["configured"]).to.be.false - }) - -}) diff --git a/test/src/commands/config/get.ts b/test/src/commands/get.ts similarity index 71% rename from test/src/commands/config/get.ts rename to test/src/commands/get.ts index ab0c44ca72..9bb1f52b76 100644 --- a/test/src/commands/config/get.ts +++ b/test/src/commands/get.ts @@ -1,11 +1,11 @@ import { expect } from "chai" -import { expectError, makeTestContextA } from "../../../helpers" -import { ConfigGetCommand } from "../../../../src/commands/config/get" +import { expectError, makeTestContextA } from "../../helpers" +import { GetConfigCommand } from "../../../src/commands/get" -describe("ConfigGetCommand", () => { +describe("GetConfigCommand", () => { it("should get a config variable", async () => { const ctx = await makeTestContextA() - const command = new ConfigGetCommand() + const command = new GetConfigCommand() await ctx.setConfig({ key: ["project", "mykey"], value: "myvalue" }) @@ -16,7 +16,7 @@ describe("ConfigGetCommand", () => { it("should throw on invalid key", async () => { const ctx = await makeTestContextA() - const command = new ConfigGetCommand() + const command = new GetConfigCommand() await expectError( async () => await command.action(ctx, { key: "bla.mykey" }), @@ -26,7 +26,7 @@ describe("ConfigGetCommand", () => { it("should throw on missing key", async () => { const ctx = await makeTestContextA() - const command = new ConfigGetCommand() + const command = new GetConfigCommand() await expectError( async () => await command.action(ctx, { key: "project.mykey" }), diff --git a/test/src/commands/config/set.ts b/test/src/commands/set.ts similarity index 67% rename from test/src/commands/config/set.ts rename to test/src/commands/set.ts index 8e8880f929..afefc0013f 100644 --- a/test/src/commands/config/set.ts +++ b/test/src/commands/set.ts @@ -1,11 +1,11 @@ import { expect } from "chai" -import { ConfigSetCommand } from "../../../../src/commands/config/set" -import { expectError, makeTestContextA } from "../../../helpers" +import { SetConfigCommand } from "../../../src/commands/set" +import { expectError, makeTestContextA } from "../../helpers" -describe("ConfigSetCommand", () => { +describe("SetConfigCommand", () => { it("should set a config variable", async () => { const ctx = await makeTestContextA() - const command = new ConfigSetCommand() + const command = new SetConfigCommand() await command.action(ctx, { key: "project.mykey", value: "myvalue" }) @@ -14,7 +14,7 @@ describe("ConfigSetCommand", () => { it("should throw on invalid key", async () => { const ctx = await makeTestContextA() - const command = new ConfigSetCommand() + const command = new SetConfigCommand() await expectError( async () => await command.action(ctx, { key: "bla.mykey", value: "ble" }),