From 27ae57f6140cb8c136c74c38d415afdcadb58ddd Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Mon, 28 May 2018 19:12:08 -0300 Subject: Tests: cache build of mock server dependencies to speed up tests --- spec/build_spec.lua | 4 +-- spec/new_version_spec.lua | 4 +-- spec/pack_spec.lua | 32 ++++++++++--------- spec/upload_spec.lua | 4 +-- spec/util/test_env.lua | 75 +++++++++++++++++++++++++------------------- spec/write_rockspec_spec.lua | 3 -- 6 files changed, 65 insertions(+), 57 deletions(-) diff --git a/spec/build_spec.lua b/spec/build_spec.lua index cbe061c3..2e7333b3 100644 --- a/spec/build_spec.lua +++ b/spec/build_spec.lua @@ -5,7 +5,7 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() -local extra_rocks = test_env.mock_server_extra_rocks({ +local extra_rocks = { "/lmathx-20120430.51-1.src.rock", "/lmathx-20120430.51-1.rockspec", "/lmathx-20120430.52-1.src.rock", @@ -26,7 +26,7 @@ local extra_rocks = test_env.mock_server_extra_rocks({ "/lxsh-0.8.6-2.rockspec", "/stdlib-41.0.0-1.src.rock", "/validate-args-1.5.4-1.rockspec" -}) +} describe("LuaRocks build tests #blackbox #b_build", function() diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 3d9d5cab..f3bb007e 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua @@ -5,10 +5,10 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() -local extra_rocks = test_env.mock_server_extra_rocks({ +local extra_rocks = { "/abelhas-1.1-1.rockspec", "/lpeg-0.12-1.rockspec" -}) +} describe("LuaRocks new_version tests #blackbox #b_new_version", function() diff --git a/spec/pack_spec.lua b/spec/pack_spec.lua index 54d139e0..8fbade44 100644 --- a/spec/pack_spec.lua +++ b/spec/pack_spec.lua @@ -5,14 +5,14 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() -local extra_rocks = test_env.mock_server_extra_rocks({ +local extra_rocks = { "/luasec-0.6-1.rockspec", "/luassert-1.7.0-1.src.rock", "/luasocket-3.0rc1-2.src.rock", "/luasocket-3.0rc1-2.rockspec", "/say-1.2-1.src.rock", "/say-1.0-1.src.rock" -}) +} describe("LuaRocks pack #blackbox #b_pack", function() @@ -50,14 +50,7 @@ describe("LuaRocks pack #blackbox #b_pack", function() assert(test_env.remove_files(lfs.currentdir(), "say%-")) end) - it("src", function() - assert(run.luarocks_bool("install luasec " .. test_env.OPENSSL_DIRS)) - assert(run.luarocks_bool("download --rockspec luasocket 3.0rc1-2")) - assert(run.luarocks_bool("pack luasocket-3.0rc1-2.rockspec")) - assert(test_env.remove_files(lfs.currentdir(), "luasocket%-")) - end) - - describe("#mock namespaced dependencies", function() + describe("#mock", function() setup(function() test_env.mock_server_init() @@ -67,12 +60,23 @@ describe("LuaRocks pack #blackbox #b_pack", function() test_env.mock_server_done() end) - it("can pack rockspec with namespaced dependencies", function() + it("can pack a rockspec into a .src.rock", function() finally(function() - os.remove("has_namespaced_dep-1.0-1.src.rock") + os.remove("a_rock-1.0-1.src.rock") + end) + assert(run.luarocks_bool("download --rockspec --server=" .. testing_paths.fixtures_dir .. "/a_repo a_rock 1.0-1")) + assert(run.luarocks_bool("pack a_rock-1.0-1.rockspec")) + assert.is_truthy(lfs.attributes("a_rock-1.0-1.src.rock")) + end) + + describe("namespaced dependencies", function() + it("can pack rockspec with namespaced dependencies", function() + finally(function() + os.remove("has_namespaced_dep-1.0-1.src.rock") + end) + assert(run.luarocks_bool("pack " .. testing_paths.fixtures_dir .. "/a_repo/has_namespaced_dep-1.0-1.rockspec")) + assert.is_truthy(lfs.attributes("has_namespaced_dep-1.0-1.src.rock")) end) - assert(run.luarocks_bool("pack " .. testing_paths.fixtures_dir .. "/a_repo/has_namespaced_dep-1.0-1.rockspec")) - assert.is_truthy(lfs.attributes("has_namespaced_dep-1.0-1.src.rock")) end) end) diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index 3adfa2dd..a54f21c5 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua @@ -4,12 +4,10 @@ local testing_paths = test_env.testing_paths test_env.unload_luarocks() -local extra_rocks = test_env.mock_server_extra_rocks() - describe("LuaRocks upload tests #blackbox #b_upload", function() before_each(function() - test_env.setup_specs(extra_rocks) + test_env.setup_specs() end) it("LuaRocks upload with no flags/arguments", function() diff --git a/spec/util/test_env.lua b/spec/util/test_env.lua index 48914311..b3b9bb77 100644 --- a/spec/util/test_env.lua +++ b/spec/util/test_env.lua @@ -317,12 +317,12 @@ end -- @param save_path string: path to directory, where to download rocks/rockspecs -- @return make_manifest boolean: true if new rocks downloaded local function download_rocks(urls, save_path) - local luarocks_repo = "https://luarocks.org" + local luarocks_repo = "https://luarocks.org/" local make_manifest = false for _, url in ipairs(urls) do -- check if already downloaded - if not test_env.exists(save_path .. url) then + if not test_env.exists(save_path .. "/" .. url) then if test_env.TEST_TARGET_OS == "windows" then assert(execute_bool(test_env.testing_paths.win_tools .. "/wget -cP " .. save_path .. " " .. luarocks_repo .. url .. " --no-check-certificate")) else @@ -442,6 +442,14 @@ local function make_run_functions() } end +local function move_file(src, dst) + if test_env.TEST_TARGET_OS == "windows" then + execute_bool(test_env.testing_paths.win_tools .. "/mv " .. src .. " " .. dst) + else + execute_bool("mv " .. src .. " " .. dst) + end +end + --- Rebuild environment. -- Remove old installed rocks and install new ones, -- updating manifests and tree copies. @@ -461,13 +469,9 @@ local function build_environment(rocks, env_variables) for _, rock in ipairs(rocks) do if not test_env.run.luarocks_nocov("install --only-server=" .. testing_paths.testing_cache .. " --tree=" .. testing_paths.testing_sys_tree .. " " .. Q(rock), env_variables) then - test_env.run.luarocks_nocov("build --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock) .. "", env_variables) + test_env.run.luarocks_nocov("build --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables) test_env.run.luarocks_nocov("pack --tree=" .. Q(testing_paths.testing_sys_tree) .. " " .. Q(rock), env_variables) - if test_env.TEST_TARGET_OS == "windows" then - execute_bool(testing_paths.win_tools .. "/mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) - else - execute_bool("mv " .. rock .. "-*.rock " .. testing_paths.testing_cache) - end + move_file(rock .. "-*.rock", testing_paths.testing_cache) end end @@ -740,31 +744,6 @@ local function install_luarocks(install_env_vars) print("LuaRocks installed correctly!") end -function test_env.mock_server_extra_rocks(more) - local rocks = { - -- rocks needed for mock-server - "/copas-2.0.1-1.src.rock", - "/coxpcall-1.16.0-1.src.rock", - "/dkjson-2.5-2.src.rock", - "/luafilesystem-1.6.3-1.src.rock", - "/luasec-0.6-1.rockspec", - "/luasocket-3.0rc1-2.src.rock", - "/luasocket-3.0rc1-2.rockspec", - "/restserver-0.1-1.src.rock", - "/restserver-xavante-0.2-1.src.rock", - "/rings-1.3.0-1.src.rock", - "/wsapi-1.6.1-1.src.rock", - "/wsapi-xavante-1.6.1-1.src.rock", - "/xavante-2.4.0-1.src.rock" - } - if more then - for _, rock in ipairs(more) do - table.insert(rocks, rock) - end - end - return rocks -end - function test_env.mock_server_init() local testing_paths = test_env.testing_paths assert(test_env.need_rock("restserver-xavante")) @@ -789,6 +768,33 @@ function test_env.mock_server_done() end end +local function prepare_mock_server_binary_rocks() + local testing_paths = test_env.testing_paths + + local rocks = { + -- rocks needed for mock-server + "luasocket-3.0rc1-2.src.rock", + "coxpcall-1.16.0-1.src.rock", + "copas-2.0.1-1.src.rock", + "luafilesystem-1.7.0-2.src.rock", + "xavante-2.4.0-1.src.rock", + "wsapi-1.6.1-1.src.rock", + "rings-1.3.0-1.src.rock", + "wsapi-xavante-1.6.1-1.src.rock", + "dkjson-2.5-2.src.rock", + "restserver-0.1-1.src.rock", + "restserver-xavante-0.2-1.src.rock", + } + download_rocks(rocks, testing_paths.testing_server) + for _, rock in ipairs(rocks) do + test_env.run.luarocks_nocov("build " .. Q(testing_paths.testing_server .. "/" .. rock) .. " --tree=" .. testing_paths.testing_cache) + local rockname = rock:gsub("%-[^-]+%-%d+%.[%a.]+$", "") + test_env.run.luarocks_nocov("pack " .. rockname .. " --tree=" .. testing_paths.testing_cache) + move_file(rockname .. "-*.rock", testing_paths.testing_server) + end + test_env.run.luarocks_admin_nocov("make_manifest " .. Q(testing_paths.testing_server)) +end + --- -- Main function to create config files and testing environment function test_env.main() @@ -837,7 +843,10 @@ function test_env.main() -- Download rocks needed for LuaRocks testing environment lfs.mkdir(testing_paths.testing_server) download_rocks(urls, testing_paths.testing_server) + build_environment(rocks, install_env_vars) + + prepare_mock_server_binary_rocks() end test_env.set_lua_version() diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index 0a0988d0..95dc87ff 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua @@ -3,8 +3,6 @@ local git_repo = require("spec.util.git_repo") local lfs = require("lfs") local run = test_env.run -local extra_rocks = test_env.mock_server_extra_rocks() - describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() before_each(function() @@ -79,7 +77,6 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() describe("from tarball #mock", function() setup(function() - test_env.setup_specs(extra_rocks) test_env.mock_server_init() end) teardown(function() -- cgit v1.2.3-55-g6feb