aboutsummaryrefslogtreecommitdiff
path: root/spec/util/git_repo.lua
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2018-03-30 15:22:09 -0300
committerHisham Muhammad <hisham@gobolinux.org>2018-03-30 19:52:17 -0300
commit2dc0a68c941d883753b2d6715921a8952f95204b (patch)
tree57c45b68dfd9041ad6484aac1f3be0b11ac706ce /spec/util/git_repo.lua
parent43adf5df7465c39a9f6fc735654aabac991cabb5 (diff)
downloadluarocks-2dc0a68c941d883753b2d6715921a8952f95204b.tar.gz
luarocks-2dc0a68c941d883753b2d6715921a8952f95204b.tar.bz2
luarocks-2dc0a68c941d883753b2d6715921a8952f95204b.zip
Tests: run our own local git-daemon repository for git tests
Diffstat (limited to 'spec/util/git_repo.lua')
-rw-r--r--spec/util/git_repo.lua107
1 files changed, 107 insertions, 0 deletions
diff --git a/spec/util/git_repo.lua b/spec/util/git_repo.lua
new file mode 100644
index 00000000..6cccfcc4
--- /dev/null
+++ b/spec/util/git_repo.lua
@@ -0,0 +1,107 @@
1local git_repo = {}
2
3local test_env = require("spec.util.test_env")
4local lfs = require("lfs")
5
6local files = {
7----------------------------------------
8["testrock-dev-1.rockspec"] = [[
9package = "testrock"
10version = "dev-1"
11source = {
12 url = "git://localhost:20000/testrock"
13}
14description = {
15 homepage = "https://localhost",
16 license = "MIT"
17}
18dependencies = {}
19build = {
20 type = "builtin",
21 modules = {
22 testrock = "testrock.lua"
23 }
24}
25]],
26----------------------------------------
27["testrock.lua"] = [[
28local testrock = {}
29
30function testrock.say()
31 return "Hello, world!"
32end
33
34return testrock
35]],
36----------------------------------------
37["foo.c"] = [[
38#include <lua.h>
39int luaopen_foo(lua_State* L) {
40 lua_pushnumber(L, 42);
41 return 1;
42}
43]],
44----------------------------------------
45["test.lua"] = [[
46print("this should be ignored!")
47]],
48}
49
50local function write_file(filename, contents)
51 local fd = assert(io.open(filename, "w"))
52 assert(fd:write(contents))
53 fd:close()
54end
55
56local function handling(args)
57 local pok, ret = pcall(args.try)
58 if not pok then
59 pok, ret = pcall(args.catch, ret)
60 end
61 args.finally()
62 if not pok then
63 error(ret)
64 end
65 return ret
66end
67
68function git_repo.start()
69 local dir = lfs.currentdir()
70 return handling {
71 try = function()
72 local pidfile = os.tmpname()
73 local basedir = test_env.testing_paths.testrun_dir .. "/git_repo"
74 local repodir = basedir .. "/testrock"
75 test_env.remove_dir(basedir)
76 lfs.mkdir(basedir)
77 lfs.mkdir(repodir)
78 lfs.chdir(repodir)
79 assert(test_env.execute("git init"))
80 for name, contents in pairs(files) do
81 write_file(name, contents)
82 test_env.execute("git add " .. name)
83 end
84 assert(test_env.execute("git commit -a -m 'initial commit'"))
85 print("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &")
86 assert(test_env.execute("git daemon --reuseaddr --pid-file="..pidfile.." --base-path="..basedir.." --export-all "..repodir.." &"))
87 assert(test_env.execute("sleep 0.1; netstat -ln | grep '0.0.0.0:9418 .* LISTEN'"))
88 return {
89 stop = function()
90 local fd = io.open(pidfile)
91 local pid = fd:read("*a")
92 fd:close()
93 assert(test_env.execute("kill -HUP " .. pid))
94 test_env.remove_dir(basedir)
95 end
96 }
97 end,
98 catch = function(err)
99 error(err)
100 end,
101 finally = function()
102 lfs.chdir(dir)
103 end,
104 }
105end
106
107return git_repo