Files
soldr-modules/auditd/1.0.0/cmodule/exec_spec.lua
T
2023-02-10 17:08:54 +03:00

27 lines
694 B
Lua

package.path = package.path .. ";cmodule/?.lua"
local exec = require "exec"
local function string_contains(str, sub)
return string.find(str, sub, 1, true) ~= nil
end
describe("exec", function()
it("runs a given command", function()
assert(exec("true"))
end)
it("must fail unless the exit code is 0", function()
local ok, err = exec("echo ERROR; false")
assert(not ok)
assert(string_contains(err, 'exit=1: ERROR'),
string.format("unexpected error message: %s", err))
end)
test("a bad command", function()
local ok, err = exec("unknown-command")
assert(not ok)
assert(string_contains(err, "not found"),
string.format("unexpected error message: %s", err))
end)
end)