aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorroboo <robo.karasek@gmail.com>2016-07-17 19:20:01 +0200
committerroboo <robo.karasek@gmail.com>2016-07-17 19:20:01 +0200
commitfe8b7e8f1313f08d8aa41239f7836539a88e9c46 (patch)
treef6790096b7371757eeffa76d6bedd2b0000c2355 /test
parent42de075dd63cb35107c514b55c061bf43f3ed184 (diff)
downloadluarocks-fe8b7e8f1313f08d8aa41239f7836539a88e9c46.tar.gz
luarocks-fe8b7e8f1313f08d8aa41239f7836539a88e9c46.tar.bz2
luarocks-fe8b7e8f1313f08d8aa41239f7836539a88e9c46.zip
New upload tests with mock-server
Diffstat (limited to 'test')
-rw-r--r--test/luarocks_site.lua6
-rw-r--r--test/mock-server.lua80
2 files changed, 86 insertions, 0 deletions
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
2upload = {
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.
4local restserver = require("restserver")
5local server = restserver:new():port(8080)
6
7server: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
19server: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
31server: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
43server: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
55server: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
68server: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
80server:enable("restserver.xavante"):start() \ No newline at end of file