Skip to content

Commit

Permalink
add some environment override tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Jan 9, 2023
1 parent 59d746e commit 08c0838
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lapis/cmd/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,22 @@ local COMMANDS = {
args["preload-module"] = args.preload_module
return action[1](self, args, unpack(args.files))
end
},
{
name = "debug",
hidden = true,
help = "Debug information for test sutie",
test_available = function()
local running_in_test
running_in_test = require("lapis.spec").running_in_test
return running_in_test()
end,
argparse = function(command)
return add_environment_argument(command)
end,
function(self, args)
return args
end
}
}
local CommandRunner
Expand Down
14 changes: 14 additions & 0 deletions lapis/cmd/actions.moon
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,20 @@ COMMANDS = {
args["preload-module"] = args.preload_module
action[1] @, args, unpack args.files
}

{
name: "debug"
hidden: true
help: "Debug information for test sutie"
test_available: ->
import running_in_test from require "lapis.spec"
running_in_test!

argparse: (command) ->
add_environment_argument command

(args) => args
}
}

class CommandRunner
Expand Down
22 changes: 22 additions & 0 deletions spec/cmd_spec.moon
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,28 @@ describe "lapis.cmd.actions.execute", ->
table.sort have_files
assert.same files, have_files

describe "debug", ->
it "gets default environment with no overrides", ->
res = cmd.execute { "debug" }
assert.same "test", res.environment

it "environment with --environment", ->
res = cmd.execute { "debug", "--environment", "cool" }
assert.same "cool", res.environment

res = cmd.execute { "--environment", "cool", "debug" }
assert.same "cool", res.environment

it "environment with arg", ->
res = cmd.execute { "debug", "wow" }
assert.same "wow", res.environment

it "fails with double env", ->
assert.has_error(
-> cmd.execute { "--environment=umm", "debug", "wow" }
"You tried to set the environment twice. Use either --environment or the environment argument, not both"
)

describe "new", ->
before_each ->
stub(require("lapis.cmd.nginx"), "find_nginx").returns true
Expand Down

0 comments on commit 08c0838

Please sign in to comment.