-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
845bf59
commit 8219762
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |