diff options
author | roboo <robo.karasek@gmail.com> | 2016-07-17 19:20:01 +0200 |
---|---|---|
committer | roboo <robo.karasek@gmail.com> | 2016-07-17 19:20:01 +0200 |
commit | fe8b7e8f1313f08d8aa41239f7836539a88e9c46 (patch) | |
tree | f6790096b7371757eeffa76d6bedd2b0000c2355 | |
parent | 42de075dd63cb35107c514b55c061bf43f3ed184 (diff) | |
download | luarocks-fe8b7e8f1313f08d8aa41239f7836539a88e9c46.tar.gz luarocks-fe8b7e8f1313f08d8aa41239f7836539a88e9c46.tar.bz2 luarocks-fe8b7e8f1313f08d8aa41239f7836539a88e9c46.zip |
New upload tests with mock-server
-rw-r--r-- | spec/upload_spec.lua | 47 | ||||
-rw-r--r-- | test/luarocks_site.lua | 6 | ||||
-rw-r--r-- | test/mock-server.lua | 80 |
3 files changed, 132 insertions, 1 deletions
diff --git a/spec/upload_spec.lua b/spec/upload_spec.lua index c10ef0e9..ee397ed4 100644 --- a/spec/upload_spec.lua +++ b/spec/upload_spec.lua | |||
@@ -1,10 +1,37 @@ | |||
1 | local test_env = require("test/test_environment") | 1 | local test_env = require("test/test_environment") |
2 | local run = test_env.run | 2 | local run = test_env.run |
3 | local testing_paths = test_env.testing_paths | ||
3 | 4 | ||
4 | test_env.unload_luarocks() | 5 | test_env.unload_luarocks() |
5 | 6 | ||
6 | local extra_rocks = { | 7 | local extra_rocks = { |
7 | "/lua-cjson-2.1.0-1.src.rock" | 8 | "/lua-cjson-2.1.0-1.src.rock", |
9 | |||
10 | "/copas-2.0.1-1.src.rock", | ||
11 | "/coxpcall-1.16.0-1.src.rock", | ||
12 | "/dkjson-2.5-2.src.rock", | ||
13 | "/luafilesystem-1.6.3-1.src.rock", | ||
14 | "/luasec-0.6-1.rockspec", | ||
15 | "/luasocket-3.0rc1-1.src.rock", | ||
16 | "/luasocket-3.0rc1-1.rockspec", | ||
17 | "/restserver-0.1-1.src.rock", | ||
18 | "/restserver-xavante-0.2-1.src.rock", | ||
19 | "/rings-1.3.0-1.src.rock", | ||
20 | "/wsapi-1.6.1-1.src.rock", | ||
21 | "/wsapi-xavante-1.6.1-1.src.rock", | ||
22 | "/xavante-2.4.0-1.src.rock" | ||
23 | -- "copas 2.0.1-1", | ||
24 | -- coxpcall 1.16.0-1 | ||
25 | -- dkjson 2.5-2 | ||
26 | -- luafilesystem 1.6.3-2 | ||
27 | -- luasec 0.6-1 | ||
28 | -- luasocket 3.0rc1-2 | ||
29 | -- restserver 0.1-1 | ||
30 | -- restserver-xavante 0.2-1 | ||
31 | -- rings 1.3.0-1 | ||
32 | -- wsapi 1.6.1-1 | ||
33 | -- wsapi-xavante 1.6.1-1 | ||
34 | -- xavante 2.4.0-1 | ||
8 | } | 35 | } |
9 | 36 | ||
10 | describe("LuaRocks upload tests #blackbox #b_upload", function() | 37 | describe("LuaRocks upload tests #blackbox #b_upload", function() |
@@ -34,6 +61,24 @@ describe("LuaRocks upload tests #blackbox #b_upload", function() | |||
34 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force luacov-0.11.0-1.rockspec")) | 61 | assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force luacov-0.11.0-1.rockspec")) |
35 | assert.is_true(run.luarocks_bool("install lua-cjson")) | 62 | assert.is_true(run.luarocks_bool("install lua-cjson")) |
36 | end) | 63 | end) |
64 | |||
65 | describe("LuaRocks upload tests with Xavante server", function() | ||
66 | before_each(function() | ||
67 | assert.is_true(test_env.need_rock("restserver-xavante")) | ||
68 | os.execute(testing_paths.lua .. " " .. testing_paths.testing_dir .. "/mock-server.lua &") | ||
69 | end) | ||
70 | |||
71 | after_each(function() | ||
72 | os.execute("curl localhost:8080/shutdown") | ||
73 | end) | ||
74 | |||
75 | it("LuaRocks upload rockspec with api-key", function() | ||
76 | assert.is_true(run.luarocks_bool("upload " .. testing_paths.testing_server .. "/luasocket-3.0rc1-1.rockspec --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) | ||
77 | end) | ||
78 | it("LuaRocks upload rockspec with api-key and skip-pack", function() | ||
79 | assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.testing_server .. "/luasocket-3.0rc1-1.rockspec --api-key=123", {LUAROCKS_CONFIG = testing_paths.testing_dir .. "/luarocks_site.lua"})) | ||
80 | end) | ||
81 | end) | ||
37 | end) | 82 | end) |
38 | 83 | ||
39 | 84 | ||
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 @@ | |||
1 | -- Config file of LuaRocks site for tests | ||
2 | upload = { | ||
3 | server = "http://localhost:8080", | ||
4 | tool_version = "1.0.0", | ||
5 | api_version = "1", | ||
6 | } \ 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 @@ | |||
1 | #!/usr/bin/env lua | ||
2 | |||
3 | --- A simple LuaRocks mock-server for testing. | ||
4 | local restserver = require("restserver") | ||
5 | local server = restserver:new():port(8080) | ||
6 | |||
7 | server:add_resource("api/tool_version", { | ||
8 | { | ||
9 | method = "GET", | ||
10 | path = "/", | ||
11 | produces = "application/json", | ||
12 | handler = function(query) | ||
13 | local json = { version = query.current } | ||
14 | return restserver.response():status(200):entity(json) | ||
15 | end | ||
16 | } | ||
17 | }) | ||
18 | |||
19 | server:add_resource("api/1/{id:[0-9]+}/status", { | ||
20 | { | ||
21 | method = "GET", | ||
22 | path = "/", | ||
23 | produces = "application/json", | ||
24 | handler = function(query) | ||
25 | local json = { user_id = "123", created_at = "29.1.1993" } | ||
26 | return restserver.response():status(200):entity(json) | ||
27 | end | ||
28 | } | ||
29 | }) | ||
30 | |||
31 | server:add_resource("/api/1/{id:[0-9]+}/check_rockspec", { | ||
32 | { | ||
33 | method = "GET", | ||
34 | path = "/", | ||
35 | produces = "application/json", | ||
36 | handler = function(query) | ||
37 | local json = {} | ||
38 | return restserver.response():status(200):entity(json) | ||
39 | end | ||
40 | } | ||
41 | }) | ||
42 | |||
43 | server:add_resource("/api/1/{id:[0-9]+}/upload", { | ||
44 | { | ||
45 | method = "POST", | ||
46 | path = "/", | ||
47 | produces = "application/json", | ||
48 | handler = function(query) | ||
49 | local json = {module = "luasocket", version = {id = "1.0"}, module_url = "http://localhost/luasocket", manifests = "root", is_new = "is_new"} | ||
50 | return restserver.response():status(200):entity(json) | ||
51 | end | ||
52 | } | ||
53 | }) | ||
54 | |||
55 | server:add_resource("/api/1/{id:[0-9]+}/upload_rock/{id:[0-9]+}", { | ||
56 | { | ||
57 | method = "POST", | ||
58 | path = "/", | ||
59 | produces = "application/json", | ||
60 | handler = function(query) | ||
61 | local json = {"rock","module_url"} | ||
62 | return restserver.response():status(200):entity(json) | ||
63 | end | ||
64 | } | ||
65 | }) | ||
66 | |||
67 | -- SHUTDOWN this mock-server | ||
68 | server:add_resource("/shutdown", { | ||
69 | { | ||
70 | method = "GET", | ||
71 | path = "/", | ||
72 | handler = function(query) | ||
73 | os.exit() | ||
74 | return restserver.response():status(200):entity() | ||
75 | end | ||
76 | } | ||
77 | }) | ||
78 | |||
79 | -- This loads the restserver.xavante plugin | ||
80 | server:enable("restserver.xavante"):start() \ No newline at end of file | ||