Skip to content

Commit

Permalink
IO tests
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed May 9, 2015
1 parent 845bf59 commit 8219762
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions spec/unit/tools/io_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local IO = require "kong.tools.io"

local TEST_FILE = "/tmp/test_file"

describe("IO", function()

before_each(function()
os.remove(TEST_FILE)
end)

it("should detect existing commands", function()
assert.truthy(IO.cmd_exists("hash"))
assert.falsy(IO.cmd_exists("hashasdasd"))
end)

it("should write and read from files", function()
assert.truthy(IO.write_to_file(TEST_FILE, "this is a test"))
assert.are.same("this is a test", IO.read_file(TEST_FILE))
end)

it("should detect existing files", function()
assert.falsy(IO.file_exists(TEST_FILE))
IO.write_to_file(TEST_FILE, "Test")
assert.truthy(IO.cmd_exists(TEST_FILE))
end)

it("should execute an OS command", function()
local res, code = IO.os_execute("echo \"Hello\"")
assert.are.same(0, code)
assert.truthy("Hello", res)

local res, code = IO.os_execute("asdasda \"Hello\"")
assert.are.same(127, code)
assert.are.same("/bin/bash: asdasda: command not found", res)
end)

end)

0 comments on commit 8219762

Please sign in to comment.