From 8219762788f35420caf0c35e12a5f9647eb3c77d Mon Sep 17 00:00:00 2001 From: thefosk Date: Fri, 8 May 2015 18:31:53 -0700 Subject: [PATCH] IO tests --- spec/unit/tools/io_spec.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/unit/tools/io_spec.lua diff --git a/spec/unit/tools/io_spec.lua b/spec/unit/tools/io_spec.lua new file mode 100644 index 00000000000..3bbca4941e1 --- /dev/null +++ b/spec/unit/tools/io_spec.lua @@ -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)