Skip to content

Commit

Permalink
test: test specs to describe the expected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
vvagaytsev committed Oct 13, 2023
1 parent d189d76 commit b6d9086
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions core/test/unit/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,96 @@ describe("cli", () => {
})
})

context("exit codes", () => {
const cwd = getDataDir("test-project-a")

context("garden binary", () => {
it("garden exits with code 0 on no flags", async () => {
const res = await cli.run({ args: [], exitOnError: false, cwd })

expect(res.code).to.equal(0)
})

it("garden exits with code 0 on recognized flag", async () => {
const res = await cli.run({ args: ["--help"], exitOnError: false, cwd })

expect(res.code).to.equal(0)
})

it("garden exits with code 1 on unrecognized flag", async () => {
const res = await cli.run({ args: ["--i-am-groot"], exitOnError: false, cwd })

expect(res.code).to.equal(1)
})

it("garden exits with code 0 on recognized command", async () => {
const res = await cli.run({ args: ["validate"], exitOnError: false, cwd })

expect(res.code).to.equal(0)
})

it("garden exits with code 1 on unrecognized command", async () => {
const res = await cli.run({ args: ["baby-groot"], exitOnError: false, cwd })

expect(res.code).to.equal(1)
})
})

context("garden command without sub-commands", () => {
it("garden command exits with code 0 on recognized flag", async () => {
const res = await cli.run({ args: ["validate", "--help"], exitOnError: false, cwd })

expect(res.code).to.equal(0)
})

it("garden command exits with code 1 on unrecognized flag", async () => {
const res = await cli.run({ args: ["validate", "--i-am-groot"], exitOnError: false, cwd })

expect(res.code).to.equal(1)
})
})

context("garden command with sub-commands", () => {
it("garden command exits with code 0 on recognized flag", async () => {
const res = await cli.run({ args: ["get", "--help"], exitOnError: false, cwd })

expect(res.code).to.equal(0)
})

it("garden command exits with code 1 on unrecognized flag", async () => {
const res = await cli.run({ args: ["get", "--i-am-groot"], exitOnError: false, cwd })

expect(res.code).to.equal(1)
})

it("garden command exits with code 0 on recognized sub-command", async () => {
const res = await cli.run({ args: ["get", "actions"], exitOnError: false, cwd })

expect(res.code).to.equal(0)
})

it("garden command exits with code 1 on unrecognized sub-command", async () => {
const res = await cli.run({ args: ["get", "baby-groot"], exitOnError: false, cwd })

expect(res.code).to.equal(1)
})
})

context("garden sub-command", () => {
it("garden sub-command exits with code 0 on recognized flag", async () => {
const res = await cli.run({ args: ["get", "actions", "--help"], exitOnError: false, cwd })

expect(res.code).to.equal(0)
})

it("garden sub-command exits with code 1 on unrecognized flag", async () => {
const res = await cli.run({ args: ["get", "actions", "--i-am-groot"], exitOnError: false, cwd })

expect(res.code).to.equal(1)
})
})
})

context("test logger initialization", () => {
const envLoggerType = process.env.GARDEN_LOGGER_TYPE
const envLogLevel = process.env.GARDEN_LOG_LEVEL
Expand Down

0 comments on commit b6d9086

Please sign in to comment.