diff options
author | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-12 16:03:58 -0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-14 14:06:51 -0300 |
commit | b159a8e28d3419e19b1851c7536220eb0eb3b356 (patch) | |
tree | 5a03f39c55c3164758e1b15f2d4c792225f6e914 /spec | |
parent | e9396d35720fc17a20ae67d9d2b53d5058f65f39 (diff) | |
download | luarocks-b159a8e28d3419e19b1851c7536220eb0eb3b356.tar.gz luarocks-b159a8e28d3419e19b1851c7536220eb0eb3b356.tar.bz2 luarocks-b159a8e28d3419e19b1851c7536220eb0eb3b356.zip |
Tests: fix fetch tests using the rockspecs module
Diffstat (limited to 'spec')
-rw-r--r-- | spec/fetch_spec.lua | 87 |
1 files changed, 21 insertions, 66 deletions
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index 3564bffe..9a10b58d 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua | |||
@@ -5,11 +5,12 @@ test_env.unload_luarocks() | |||
5 | test_env.setup_specs() | 5 | test_env.setup_specs() |
6 | local fetch = require("luarocks.fetch") | 6 | local fetch = require("luarocks.fetch") |
7 | local path = require("luarocks.path") | 7 | local path = require("luarocks.path") |
8 | local rockspecs = require("luarocks.rockspecs") | ||
8 | local lfs = require("lfs") | 9 | local lfs = require("lfs") |
9 | local testing_paths = test_env.testing_paths | 10 | local testing_paths = test_env.testing_paths |
10 | local get_tmp_path = test_env.get_tmp_path | 11 | local get_tmp_path = test_env.get_tmp_path |
11 | 12 | ||
12 | describe("Luarocks fetch test #unit", function() | 13 | describe("Luarocks fetch test #unit #mock", function() |
13 | local are_same_files = function(file1, file2) | 14 | local are_same_files = function(file1, file2) |
14 | return file1 == file2 or lfs.attributes(file1).ino == lfs.attributes(file2).ino | 15 | return file1 == file2 or lfs.attributes(file1).ino == lfs.attributes(file2).ino |
15 | end | 16 | end |
@@ -17,23 +18,20 @@ describe("Luarocks fetch test #unit", function() | |||
17 | local runner | 18 | local runner |
18 | 19 | ||
19 | setup(function() | 20 | setup(function() |
21 | test_env.mock_server_init() | ||
22 | |||
20 | runner = require("luacov.runner") | 23 | runner = require("luacov.runner") |
21 | runner.init(testing_paths.testrun_dir .. "/luacov.config") | 24 | runner.init(testing_paths.testrun_dir .. "/luacov.config") |
22 | runner.tick = true | 25 | runner.tick = true |
23 | end) | 26 | end) |
24 | 27 | ||
25 | teardown(function() | 28 | teardown(function() |
29 | test_env.mock_server_done() | ||
30 | |||
26 | runner.shutdown() | 31 | runner.shutdown() |
27 | end) | 32 | end) |
28 | 33 | ||
29 | describe("fetch.fetch_url #mock", function() | 34 | describe("fetch.fetch_url", function() |
30 | setup(function() | ||
31 | test_env.mock_server_init() | ||
32 | end) | ||
33 | |||
34 | teardown(function() | ||
35 | test_env.mock_server_done() | ||
36 | end) | ||
37 | 35 | ||
38 | it("fetches the url argument and returns the absolute path of the fetched file", function() | 36 | it("fetches the url argument and returns the absolute path of the fetched file", function() |
39 | local fetchedfile = fetch.fetch_url("http://localhost:8080/file/a_rock.lua") | 37 | local fetchedfile = fetch.fetch_url("http://localhost:8080/file/a_rock.lua") |
@@ -62,7 +60,7 @@ describe("Luarocks fetch test #unit", function() | |||
62 | end) | 60 | end) |
63 | end) | 61 | end) |
64 | 62 | ||
65 | describe("fetch.fetch_url_at_temp_dir #mock", function() | 63 | describe("fetch.fetch_url_at_temp_dir", function() |
66 | local tmpfile | 64 | local tmpfile |
67 | local tmpdir | 65 | local tmpdir |
68 | 66 | ||
@@ -76,15 +74,7 @@ describe("Luarocks fetch test #unit", function() | |||
76 | tmpdir = nil | 74 | tmpdir = nil |
77 | end | 75 | end |
78 | end) | 76 | end) |
79 | 77 | ||
80 | setup(function() | ||
81 | test_env.mock_server_init() | ||
82 | end) | ||
83 | |||
84 | teardown(function() | ||
85 | test_env.mock_server_done() | ||
86 | end) | ||
87 | |||
88 | it("returns the absolute path and the parent directory of the file specified by the url", function() | 78 | it("returns the absolute path and the parent directory of the file specified by the url", function() |
89 | tmpdir = get_tmp_path() | 79 | tmpdir = get_tmp_path() |
90 | lfs.mkdir(tmpdir) | 80 | lfs.mkdir(tmpdir) |
@@ -130,15 +120,8 @@ describe("Luarocks fetch test #unit", function() | |||
130 | end) | 120 | end) |
131 | end) | 121 | end) |
132 | 122 | ||
133 | describe("fetch.find_base_dir #mock", function() | 123 | describe("fetch.find_base_dir", function() |
134 | setup(function() | 124 | |
135 | test_env.mock_server_init() | ||
136 | end) | ||
137 | |||
138 | teardown(function() | ||
139 | test_env.mock_server_done() | ||
140 | end) | ||
141 | |||
142 | it("extracts the archive given by the file argument and returns the inferred and the actual root directory in the archive", function() | 125 | it("extracts the archive given by the file argument and returns the inferred and the actual root directory in the archive", function() |
143 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" | 126 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" |
144 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) | 127 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) |
@@ -161,7 +144,7 @@ describe("Luarocks fetch test #unit", function() | |||
161 | end) | 144 | end) |
162 | end) | 145 | end) |
163 | 146 | ||
164 | describe("fetch.fetch_and_unpack_rock #mock", function() | 147 | describe("fetch.fetch_and_unpack_rock", function() |
165 | local tmpdir | 148 | local tmpdir |
166 | 149 | ||
167 | after_each(function() | 150 | after_each(function() |
@@ -171,14 +154,6 @@ describe("Luarocks fetch test #unit", function() | |||
171 | end | 154 | end |
172 | end) | 155 | end) |
173 | 156 | ||
174 | setup(function() | ||
175 | test_env.mock_server_init() | ||
176 | end) | ||
177 | |||
178 | teardown(function() | ||
179 | test_env.mock_server_done() | ||
180 | end) | ||
181 | |||
182 | it("unpacks the rock file from the url and returns its resulting temporary parent directory", function() | 157 | it("unpacks the rock file from the url and returns its resulting temporary parent directory", function() |
183 | tmpdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock") | 158 | tmpdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock") |
184 | assert.truthy(string.find(tmpdir, "a_rock%-1%.0%-1")) | 159 | assert.truthy(string.find(tmpdir, "a_rock%-1%.0%-1")) |
@@ -226,9 +201,9 @@ describe("Luarocks fetch test #unit", function() | |||
226 | assert.same(rockspec.name, "unknown_field") | 201 | assert.same(rockspec.name, "unknown_field") |
227 | assert.same(rockspec.version, "1.0-1") | 202 | assert.same(rockspec.version, "1.0-1") |
228 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | 203 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") |
229 | 204 | ||
230 | -- The previous calls fail if the detailed checking is done | 205 | -- The previous calls fail if the detailed checking is done |
231 | assert.falsy(pcall(fetch.load_local_rockspec, testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec")) | 206 | path.use_tree(testing_paths.testing_tree) |
232 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/missing_mandatory_field-1.0-1.rockspec")) | 207 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/missing_mandatory_field-1.0-1.rockspec")) |
233 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/unknown_field-1.0-1.rockspec")) | 208 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/unknown_field-1.0-1.rockspec")) |
234 | end) | 209 | end) |
@@ -263,15 +238,8 @@ describe("Luarocks fetch test #unit", function() | |||
263 | end) | 238 | end) |
264 | end) | 239 | end) |
265 | 240 | ||
266 | describe("fetch.load_rockspec #mock", function() | 241 | describe("fetch.load_rockspec", function() |
267 | setup(function() | 242 | |
268 | test_env.mock_server_init() | ||
269 | end) | ||
270 | |||
271 | teardown(function() | ||
272 | test_env.mock_server_done() | ||
273 | end) | ||
274 | |||
275 | it("returns a table containing the requested rockspec by downloading it into a temporary directory", function() | 243 | it("returns a table containing the requested rockspec by downloading it into a temporary directory", function() |
276 | path.use_tree(testing_paths.testing_tree) | 244 | path.use_tree(testing_paths.testing_tree) |
277 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec") | 245 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec") |
@@ -310,14 +278,7 @@ describe("Luarocks fetch test #unit", function() | |||
310 | end) | 278 | end) |
311 | end) | 279 | end) |
312 | 280 | ||
313 | describe("fetch.get_sources #mock", function() | 281 | describe("fetch.get_sources", function() |
314 | setup(function() | ||
315 | test_env.mock_server_init() | ||
316 | end) | ||
317 | |||
318 | teardown(function() | ||
319 | test_env.mock_server_done() | ||
320 | end) | ||
321 | 282 | ||
322 | it("downloads the sources for building a rock and returns the resulting source filename and its parent directory", function() | 283 | it("downloads the sources for building a rock and returns the resulting source filename and its parent directory", function() |
323 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | 284 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) |
@@ -374,20 +335,14 @@ describe("Luarocks fetch test #unit", function() | |||
374 | end) | 335 | end) |
375 | 336 | ||
376 | it("from #git", function() | 337 | it("from #git", function() |
377 | local rockspec = { | 338 | local rockspec, err = rockspecs.from_persisted_table("testrock-dev-1.rockspec", { |
378 | format_is_at_least = function() | 339 | package = "testrock", |
379 | return true | ||
380 | end, | ||
381 | name = "testrock", | ||
382 | version = "dev-1", | 340 | version = "dev-1", |
383 | source = { | 341 | source = { |
384 | protocol = "git", | ||
385 | url = "git://localhost/testrock", | 342 | url = "git://localhost/testrock", |
386 | }, | 343 | }, |
387 | variables = { | 344 | }, nil) |
388 | GIT = "git", | 345 | assert.falsy(err) |
389 | }, | ||
390 | } | ||
391 | local pathname, tmpdir = fetch.fetch_sources(rockspec, false) | 346 | local pathname, tmpdir = fetch.fetch_sources(rockspec, false) |
392 | assert.are.same("testrock", pathname) | 347 | assert.are.same("testrock", pathname) |
393 | assert.match("luarocks_testrock%-dev%-1%-", tmpdir) | 348 | assert.match("luarocks_testrock%-dev%-1%-", tmpdir) |