diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2017-10-08 14:57:41 -0400 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2017-10-08 14:57:41 -0400 |
| commit | 5aa06d43a86754f30347813803f2a9eb6f99a611 (patch) | |
| tree | b4a0efac8c80caf273dc41764b139cfa3ea9af39 | |
| parent | fa91718c540542d94e8bf7df94e9fdf0cd170569 (diff) | |
| download | luarocks-5aa06d43a86754f30347813803f2a9eb6f99a611.tar.gz luarocks-5aa06d43a86754f30347813803f2a9eb6f99a611.tar.bz2 luarocks-5aa06d43a86754f30347813803f2a9eb6f99a611.zip | |
Tests: move mock-server utils into test_environment.lua
This avoids trouble with changing package.paths during
tests.
| -rw-r--r-- | spec/new_version_spec.lua | 7 | ||||
| -rw-r--r-- | spec/upload_spec.lua | 7 | ||||
| -rw-r--r-- | test/test_environment.lua | 37 | ||||
| -rw-r--r-- | test/test_mock_server.lua | 43 |
4 files changed, 43 insertions, 51 deletions
diff --git a/spec/new_version_spec.lua b/spec/new_version_spec.lua index 6b2e2147..29449ff5 100644 --- a/spec/new_version_spec.lua +++ b/spec/new_version_spec.lua | |||
| @@ -1,12 +1,11 @@ | |||
| 1 | local test_env = require("test/test_environment") | 1 | local test_env = require("test/test_environment") |
| 2 | local test_mock_server = require("test/test_mock_server") | ||
| 3 | local lfs = require("lfs") | 2 | local lfs = require("lfs") |
| 4 | local run = test_env.run | 3 | local run = test_env.run |
| 5 | local testing_paths = test_env.testing_paths | 4 | local testing_paths = test_env.testing_paths |
| 6 | 5 | ||
| 7 | test_env.unload_luarocks() | 6 | test_env.unload_luarocks() |
| 8 | 7 | ||
| 9 | local extra_rocks = test_mock_server.extra_rocks({ | 8 | local extra_rocks = test_env.mock_server_extra_rocks({ |
| 10 | "/abelhas-1.0-1.rockspec", | 9 | "/abelhas-1.0-1.rockspec", |
| 11 | "/lpeg-0.12-1.rockspec" | 10 | "/lpeg-0.12-1.rockspec" |
| 12 | }) | 11 | }) |
| @@ -38,12 +37,12 @@ describe("LuaRocks new_version tests #blackbox #b_new_version", function() | |||
| 38 | 37 | ||
| 39 | describe("LuaRocks new_version more complex tests", function() | 38 | describe("LuaRocks new_version more complex tests", function() |
| 40 | it("LuaRocks new version with remote spec", function() | 39 | it("LuaRocks new version with remote spec", function() |
| 41 | test_mock_server.init() | 40 | test_env.mock_server_init() |
| 42 | assert.is_true(run.luarocks_bool("new_version http://localhost:8080/file/a_rock-1.0-1.rockspec")) | 41 | assert.is_true(run.luarocks_bool("new_version http://localhost:8080/file/a_rock-1.0-1.rockspec")) |
| 43 | assert.is.truthy(lfs.attributes("a_rock-1.0-1.rockspec")) | 42 | assert.is.truthy(lfs.attributes("a_rock-1.0-1.rockspec")) |
| 44 | assert.is.truthy(lfs.attributes("a_rock-1.0-2.rockspec")) | 43 | assert.is.truthy(lfs.attributes("a_rock-1.0-2.rockspec")) |
| 45 | test_env.remove_files(lfs.currentdir(), "luasocket--") | 44 | test_env.remove_files(lfs.currentdir(), "luasocket--") |
| 46 | test_mock_server.done() | 45 | test_env.mock_server_done() |
| 47 | end) | 46 | end) |
| 48 | 47 | ||
| 49 | it("LuaRocks new_version of luacov", function() | 48 | it("LuaRocks new_version of luacov", function() |
diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index cf915eb3..b8e147e0 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua | |||
| @@ -1,11 +1,10 @@ | |||
| 1 | local test_env = require("test/test_environment") | 1 | local test_env = require("test/test_environment") |
| 2 | local test_mock_server = require("test/test_mock_server") | ||
| 3 | local run = test_env.run | 2 | local run = test_env.run |
| 4 | local testing_paths = test_env.testing_paths | 3 | local testing_paths = test_env.testing_paths |
| 5 | 4 | ||
| 6 | test_env.unload_luarocks() | 5 | test_env.unload_luarocks() |
| 7 | 6 | ||
| 8 | local extra_rocks = test_mock_server.extra_rocks() | 7 | local extra_rocks = test_env.mock_server_extra_rocks() |
| 9 | 8 | ||
| 10 | describe("LuaRocks upload tests #blackbox #b_upload", function() | 9 | describe("LuaRocks upload tests #blackbox #b_upload", function() |
| 11 | 10 | ||
| @@ -35,9 +34,9 @@ describe("LuaRocks upload tests #blackbox #b_upload", function() | |||
| 35 | end) | 34 | end) |
| 36 | 35 | ||
| 37 | describe("LuaRocks upload tests with Xavante server #mock", function() | 36 | describe("LuaRocks upload tests with Xavante server #mock", function() |
| 38 | before_each(test_mock_server.init) | 37 | before_each(test_env.mock_server_init) |
| 39 | 38 | ||
| 40 | after_each(test_mock_server.done) | 39 | after_each(test_env.mock_server_done) |
| 41 | 40 | ||
| 42 | it("LuaRocks upload rockspec with api-key", function() | 41 | it("LuaRocks upload rockspec with api-key", function() |
| 43 | assert.is_true(run.luarocks_bool("upload " .. testing_paths.testing_dir .. "/testfiles/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) | 42 | assert.is_true(run.luarocks_bool("upload " .. testing_paths.testing_dir .. "/testfiles/a_rock-1.0-1.rockspec " .. test_env.OPENSSL_DIRS .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) |
diff --git a/test/test_environment.lua b/test/test_environment.lua index 56b394cd..a663c1c3 100644 --- a/test/test_environment.lua +++ b/test/test_environment.lua | |||
| @@ -685,6 +685,43 @@ local function install_luarocks(install_env_vars) | |||
| 685 | print("LuaRocks installed correctly!") | 685 | print("LuaRocks installed correctly!") |
| 686 | end | 686 | end |
| 687 | 687 | ||
| 688 | function test_env.mock_server_extra_rocks(more) | ||
| 689 | local rocks = { | ||
| 690 | -- rocks needed for mock-server | ||
| 691 | "/copas-2.0.1-1.src.rock", | ||
| 692 | "/coxpcall-1.16.0-1.src.rock", | ||
| 693 | "/dkjson-2.5-2.src.rock", | ||
| 694 | "/luafilesystem-1.6.3-1.src.rock", | ||
| 695 | "/luasec-0.6-1.rockspec", | ||
| 696 | "/luasocket-3.0rc1-2.src.rock", | ||
| 697 | "/luasocket-3.0rc1-2.rockspec", | ||
| 698 | "/restserver-0.1-1.src.rock", | ||
| 699 | "/restserver-xavante-0.2-1.src.rock", | ||
| 700 | "/rings-1.3.0-1.src.rock", | ||
| 701 | "/wsapi-1.6.1-1.src.rock", | ||
| 702 | "/wsapi-xavante-1.6.1-1.src.rock", | ||
| 703 | "/xavante-2.4.0-1.src.rock" | ||
| 704 | } | ||
| 705 | if more then | ||
| 706 | for _, rock in ipairs(more) do | ||
| 707 | table.insert(rocks, rock) | ||
| 708 | end | ||
| 709 | end | ||
| 710 | return rocks | ||
| 711 | end | ||
| 712 | |||
| 713 | function test_env.mock_server_init() | ||
| 714 | local assert = require("luassert") | ||
| 715 | local testing_paths = test_env.testing_paths | ||
| 716 | assert.is_true(test_env.need_rock("restserver-xavante")) | ||
| 717 | local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.testing_dir .. "/mock-server.lua &", true, test_env.env_variables) | ||
| 718 | os.execute(final_command) | ||
| 719 | end | ||
| 720 | |||
| 721 | function test_env.mock_server_done() | ||
| 722 | os.execute("curl localhost:8080/shutdown") | ||
| 723 | end | ||
| 724 | |||
| 688 | --- | 725 | --- |
| 689 | -- Main function to create config files and testing environment | 726 | -- Main function to create config files and testing environment |
| 690 | function test_env.main() | 727 | function test_env.main() |
diff --git a/test/test_mock_server.lua b/test/test_mock_server.lua deleted file mode 100644 index 74a57b89..00000000 --- a/test/test_mock_server.lua +++ /dev/null | |||
| @@ -1,43 +0,0 @@ | |||
| 1 | --- Utility module to launch the mock-server from within test spec files. | ||
| 2 | local test_mock_server = {} | ||
| 3 | |||
| 4 | local assert = require("luassert") | ||
| 5 | local test_env = require("test/test_environment") | ||
| 6 | local testing_paths = test_env.testing_paths | ||
| 7 | |||
| 8 | function test_mock_server.extra_rocks(more) | ||
| 9 | local rocks = { | ||
| 10 | -- rocks needed for mock-server | ||
| 11 | "/copas-2.0.1-1.src.rock", | ||
| 12 | "/coxpcall-1.16.0-1.src.rock", | ||
| 13 | "/dkjson-2.5-2.src.rock", | ||
| 14 | "/luafilesystem-1.6.3-1.src.rock", | ||
| 15 | "/luasec-0.6-1.rockspec", | ||
| 16 | "/luasocket-3.0rc1-2.src.rock", | ||
| 17 | "/luasocket-3.0rc1-2.rockspec", | ||
| 18 | "/restserver-0.1-1.src.rock", | ||
| 19 | "/restserver-xavante-0.2-1.src.rock", | ||
| 20 | "/rings-1.3.0-1.src.rock", | ||
| 21 | "/wsapi-1.6.1-1.src.rock", | ||
| 22 | "/wsapi-xavante-1.6.1-1.src.rock", | ||
| 23 | "/xavante-2.4.0-1.src.rock" | ||
| 24 | } | ||
| 25 | if more then | ||
| 26 | for _, rock in ipairs(more) do | ||
| 27 | table.insert(rocks, rock) | ||
| 28 | end | ||
| 29 | end | ||
| 30 | return rocks | ||
| 31 | end | ||
| 32 | |||
| 33 | function test_mock_server.init() | ||
| 34 | assert.is_true(test_env.need_rock("restserver-xavante")) | ||
| 35 | local final_command = test_env.execute_helper(testing_paths.lua .. " " .. testing_paths.testing_dir .. "/mock-server.lua &", true, test_env.env_variables) | ||
| 36 | os.execute(final_command) | ||
| 37 | end | ||
| 38 | |||
| 39 | function test_mock_server.done() | ||
| 40 | os.execute("curl localhost:8080/shutdown") | ||
| 41 | end | ||
| 42 | |||
| 43 | return test_mock_server | ||
