From fe8b7e8f1313f08d8aa41239f7836539a88e9c46 Mon Sep 17 00:00:00 2001 From: roboo Date: Sun, 17 Jul 2016 19:20:01 +0200 Subject: New upload tests with mock-server --- test/luarocks_site.lua | 6 ++++ test/mock-server.lua | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 test/luarocks_site.lua create mode 100644 test/mock-server.lua (limited to 'test') diff --git a/test/luarocks_site.lua b/test/luarocks_site.lua new file mode 100644 index 00000000..cfa77dca --- /dev/null +++ b/test/luarocks_site.lua @@ -0,0 +1,6 @@ +-- Config file of LuaRocks site for tests +upload = { + server = "http://localhost:8080", + tool_version = "1.0.0", + api_version = "1", +} \ No newline at end of file diff --git a/test/mock-server.lua b/test/mock-server.lua new file mode 100644 index 00000000..797e2bc5 --- /dev/null +++ b/test/mock-server.lua @@ -0,0 +1,80 @@ +#!/usr/bin/env lua + +--- A simple LuaRocks mock-server for testing. +local restserver = require("restserver") +local server = restserver:new():port(8080) + +server:add_resource("api/tool_version", { + { + method = "GET", + path = "/", + produces = "application/json", + handler = function(query) + local json = { version = query.current } + return restserver.response():status(200):entity(json) + end + } +}) + +server:add_resource("api/1/{id:[0-9]+}/status", { + { + method = "GET", + path = "/", + produces = "application/json", + handler = function(query) + local json = { user_id = "123", created_at = "29.1.1993" } + return restserver.response():status(200):entity(json) + end + } +}) + +server:add_resource("/api/1/{id:[0-9]+}/check_rockspec", { + { + method = "GET", + path = "/", + produces = "application/json", + handler = function(query) + local json = {} + return restserver.response():status(200):entity(json) + end + } +}) + +server:add_resource("/api/1/{id:[0-9]+}/upload", { + { + method = "POST", + path = "/", + produces = "application/json", + handler = function(query) + local json = {module = "luasocket", version = {id = "1.0"}, module_url = "http://localhost/luasocket", manifests = "root", is_new = "is_new"} + return restserver.response():status(200):entity(json) + end + } +}) + +server:add_resource("/api/1/{id:[0-9]+}/upload_rock/{id:[0-9]+}", { + { + method = "POST", + path = "/", + produces = "application/json", + handler = function(query) + local json = {"rock","module_url"} + return restserver.response():status(200):entity(json) + end + } +}) + +-- SHUTDOWN this mock-server +server:add_resource("/shutdown", { + { + method = "GET", + path = "/", + handler = function(query) + os.exit() + return restserver.response():status(200):entity() + end + } +}) + +-- This loads the restserver.xavante plugin +server:enable("restserver.xavante"):start() \ No newline at end of file -- cgit v1.2.3-55-g6feb From 41c8fba1bc527484809613b36eb0de23f323bb74 Mon Sep 17 00:00:00 2001 From: roboo Date: Sun, 17 Jul 2016 23:12:15 +0200 Subject: Fix of mock server setup --- spec/upload_spec.lua | 15 ++------------- test/test_environment.lua | 6 +++--- 2 files changed, 5 insertions(+), 16 deletions(-) (limited to 'test') diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index ee397ed4..b239c2f1 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua @@ -20,18 +20,6 @@ local extra_rocks = { "/wsapi-1.6.1-1.src.rock", "/wsapi-xavante-1.6.1-1.src.rock", "/xavante-2.4.0-1.src.rock" --- "copas 2.0.1-1", --- coxpcall 1.16.0-1 --- dkjson 2.5-2 --- luafilesystem 1.6.3-2 --- luasec 0.6-1 --- luasocket 3.0rc1-2 --- restserver 0.1-1 --- restserver-xavante 0.2-1 --- rings 1.3.0-1 --- wsapi 1.6.1-1 --- wsapi-xavante 1.6.1-1 --- xavante 2.4.0-1 } describe("LuaRocks upload tests #blackbox #b_upload", function() @@ -65,7 +53,8 @@ describe("LuaRocks upload tests #blackbox #b_upload", function() describe("LuaRocks upload tests with Xavante server", function() before_each(function() assert.is_true(test_env.need_rock("restserver-xavante")) - os.execute(testing_paths.lua .. " " .. testing_paths.testing_dir .. "/mock-server.lua &") + local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.testing_dir .. "/mock-server.lua &", true, test_env.env_variables) + os.execute(final_command) end) after_each(function() diff --git a/test/test_environment.lua b/test/test_environment.lua index eb545a47..dcad92cf 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -41,7 +41,7 @@ end -- @param print_command boolean: print command if 'true' -- @param env_variables table: table of environment variables to export {FOO="bar", BAR="foo"} -- @return final_command string: concatenated command to execution -local function execute_helper(command, print_command, env_variables) +function test_env.execute_helper(command, print_command, env_variables) local final_command = "" if print_command then @@ -66,7 +66,7 @@ end -- In Lua5.1 os.execute returns numeric value, but in Lua5.2+ returns boolean -- @return true/false boolean: status of the command execution local function execute_bool(command, print_command, env_variables) - command = execute_helper(command, print_command, env_variables) + command = test_env.execute_helper(command, print_command, env_variables) local ok = os.execute(command) return ok == true or ok == 0 @@ -75,7 +75,7 @@ end --- Execute command and returns output of command -- @return output string: output the command execution local function execute_output(command, print_command, env_variables) - command = execute_helper(command, print_command, env_variables) + command = test_env.execute_helper(command, print_command, env_variables) local file = assert(io.popen(command)) local output = file:read('*all') -- cgit v1.2.3-55-g6feb From 2af8f114097b2e79d7f92f9b0cea4cacdc2ff853 Mon Sep 17 00:00:00 2001 From: roboo Date: Tue, 19 Jul 2016 21:37:51 +0200 Subject: Verbose mode added --- test/test_environment.lua | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/test_environment.lua b/test/test_environment.lua index dcad92cf..5d1e8198 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua @@ -36,6 +36,18 @@ local function exists(path) return lfs.attributes(path, "mode") ~= nil end +function test_env.quiet(commad) + if not test_env.VERBOSE then + if test_env.TEST_TARGET_OS == "linux" or test_env.TEST_TARGET_OS == "osx" then + return commad .. " 1> /dev/null 2> /dev/null" + elseif test_env.TEST_TARGET_OS == "windows" then + return commad .. " 2> NUL 1> NUL" + end + else + return command + end +end + --- Helper function for execute_bool and execute_output -- @param command string: command to execute -- @param print_command boolean: print command if 'true' @@ -106,6 +118,8 @@ function test_env.set_args() test_env.RESET_ENV = false elseif argument == "clean" then test_env.TEST_ENV_CLEAN = true + elseif argument == "verbose" then + test_env.VERBOSE = true elseif argument == "travis" then test_env.TRAVIS = true elseif argument:find("^os=") then @@ -415,10 +429,11 @@ end --- Test if required rock is installed if not, install it function test_env.need_rock(rock) - if test_env.run.luarocks_nocov("show " .. rock) then + print("Check if " .. rock .. " is installed") + if test_env.run.luarocks_noprint_nocov(test_env.quiet("show " .. rock)) then return true else - return test_env.run.luarocks_nocov("install " .. rock) + return test_env.run.luarocks_noprint_nocov(test_env.quiet("install " .. rock)) end end @@ -525,18 +540,20 @@ local function clean() test_env.remove_subdirs(test_env.testing_paths.testing_dir, "testing[_%-]") test_env.remove_files(test_env.testing_paths.testing_dir, "testing_") test_env.remove_files(test_env.testing_paths.testing_dir, "luacov") + test_env.remove_files(test_env.testing_paths.testing_dir, "upload_config") print("Cleaning done!") end --- Install luarocks into testing prefix. local function install_luarocks(install_env_vars) -- Configure LuaRocks testing environment - local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. - " --prefix=" .. test_env.testing_paths.testing_lrprefix .. - " && make clean" - - assert(execute_bool(configure_cmd, false, install_env_vars)) - assert(execute_bool("make src/luarocks/site_config.lua && make dev", false, install_env_vars)) + title("Installing LuaRocks") + local configure_cmd = "./configure --with-lua=" .. test_env.testing_paths.luadir .. " --prefix=" .. test_env.testing_paths.testing_lrprefix + assert(execute_bool(test_env.quiet(configure_cmd)), false, install_env_vars) + assert(execute_bool(test_env.quiet("make clean")), false, install_env_vars) + assert(execute_bool(test_env.quiet("make src/luarocks/site_config.lua")), false, install_env_vars) + assert(execute_bool(test_env.quiet("make dev")), false, install_env_vars) + print("LuaRocks installed correctly!") end --- -- cgit v1.2.3-55-g6feb