diff options
author | George Roman <george.roman.99@gmail.com> | 2018-06-18 18:57:47 +0300 |
---|---|---|
committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-06-21 23:33:00 -0300 |
commit | bdfe731a601f3d12ffafbf504c9b06d70d5aa819 (patch) | |
tree | b6b94d398ba01fb9345d05b55c0bf2a93801cb2a /spec/fetch_spec.lua | |
parent | 48ae1d2e7705af6a7527ca61710fe18ccdb7d0b9 (diff) | |
download | luarocks-bdfe731a601f3d12ffafbf504c9b06d70d5aa819.tar.gz luarocks-bdfe731a601f3d12ffafbf504c9b06d70d5aa819.tar.bz2 luarocks-bdfe731a601f3d12ffafbf504c9b06d70d5aa819.zip |
Tests: replace small fixture files with inline content
Diffstat (limited to 'spec/fetch_spec.lua')
-rw-r--r-- | spec/fetch_spec.lua | 125 |
1 files changed, 112 insertions, 13 deletions
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index 9a10b58d..ce4cfb56 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua | |||
@@ -4,11 +4,13 @@ local git_repo = require("spec.util.git_repo") | |||
4 | test_env.unload_luarocks() | 4 | 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 fs = require("luarocks.fs") | ||
7 | local path = require("luarocks.path") | 8 | local path = require("luarocks.path") |
8 | local rockspecs = require("luarocks.rockspecs") | 9 | local rockspecs = require("luarocks.rockspecs") |
9 | local lfs = require("lfs") | 10 | local lfs = require("lfs") |
10 | local testing_paths = test_env.testing_paths | ||
11 | local get_tmp_path = test_env.get_tmp_path | 11 | local get_tmp_path = test_env.get_tmp_path |
12 | local testing_paths = test_env.testing_paths | ||
13 | local write_file = test_env.write_file | ||
12 | 14 | ||
13 | describe("Luarocks fetch test #unit #mock", function() | 15 | describe("Luarocks fetch test #unit #mock", function() |
14 | local are_same_files = function(file1, file2) | 16 | local are_same_files = function(file1, file2) |
@@ -121,7 +123,6 @@ describe("Luarocks fetch test #unit #mock", function() | |||
121 | end) | 123 | end) |
122 | 124 | ||
123 | describe("fetch.find_base_dir", function() | 125 | describe("fetch.find_base_dir", function() |
124 | |||
125 | it("extracts the archive given by the file argument and returns the inferred and the actual root directory in the archive", function() | 126 | it("extracts the archive given by the file argument and returns the inferred and the actual root directory in the archive", function() |
126 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" | 127 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" |
127 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) | 128 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) |
@@ -185,6 +186,26 @@ describe("Luarocks fetch test #unit #mock", function() | |||
185 | end) | 186 | end) |
186 | 187 | ||
187 | describe("fetch.load_local_rockspec", function() | 188 | describe("fetch.load_local_rockspec", function() |
189 | local tmpdir | ||
190 | local olddir | ||
191 | |||
192 | before_each(function() | ||
193 | tmpdir = get_tmp_path() | ||
194 | olddir = lfs.currentdir() | ||
195 | lfs.mkdir(tmpdir) | ||
196 | lfs.chdir(tmpdir) | ||
197 | fs.change_dir(tmpdir) | ||
198 | end) | ||
199 | |||
200 | after_each(function() | ||
201 | if olddir then | ||
202 | lfs.chdir(olddir) | ||
203 | if tmpdir then | ||
204 | lfs.rmdir(tmpdir) | ||
205 | end | ||
206 | end | ||
207 | end) | ||
208 | |||
188 | it("returns a table representing the rockspec from the given file skipping some checks if the quick argument is enabled", function() | 209 | it("returns a table representing the rockspec from the given file skipping some checks if the quick argument is enabled", function() |
189 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec", true) | 210 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec", true) |
190 | assert.same(rockspec.name, "a_rock") | 211 | assert.same(rockspec.name, "a_rock") |
@@ -192,20 +213,35 @@ describe("Luarocks fetch test #unit #mock", function() | |||
192 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | 213 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") |
193 | assert.same(rockspec.description, { summary = "An example rockspec" }) | 214 | assert.same(rockspec.description, { summary = "An example rockspec" }) |
194 | 215 | ||
195 | rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/missing_mandatory_field-1.0-1.rockspec", true) | 216 | write_file("missing_mandatory_field-1.0-1.rockspec", [[ |
217 | package="missing_mandatory_field" | ||
218 | version="1.0-1" | ||
219 | source = { | ||
220 | url = "http://example.com/foo.tar.gz" | ||
221 | } | ||
222 | ]], finally) | ||
223 | rockspec = fetch.load_local_rockspec("missing_mandatory_field-1.0-1.rockspec", true) | ||
196 | assert.same(rockspec.name, "missing_mandatory_field") | 224 | assert.same(rockspec.name, "missing_mandatory_field") |
197 | assert.same(rockspec.version, "1.0-1") | 225 | assert.same(rockspec.version, "1.0-1") |
198 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | 226 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") |
199 | 227 | ||
200 | rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/unknown_field-1.0-1.rockspec", true) | 228 | write_file("unknown_field-1.0-1.rockspec", [[ |
229 | package="unknown_field" | ||
230 | version="1.0-1" | ||
231 | source = { | ||
232 | url = "http://example.com/foo.tar.gz" | ||
233 | } | ||
234 | unknown="foo" | ||
235 | ]], finally) | ||
236 | rockspec = fetch.load_local_rockspec("unknown_field-1.0-1.rockspec", true) | ||
201 | assert.same(rockspec.name, "unknown_field") | 237 | assert.same(rockspec.name, "unknown_field") |
202 | assert.same(rockspec.version, "1.0-1") | 238 | assert.same(rockspec.version, "1.0-1") |
203 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | 239 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") |
204 | 240 | ||
205 | -- The previous calls fail if the detailed checking is done | 241 | -- The previous calls fail if the detailed checking is done |
206 | path.use_tree(testing_paths.testing_tree) | 242 | path.use_tree(testing_paths.testing_tree) |
207 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/missing_mandatory_field-1.0-1.rockspec")) | 243 | assert.falsy(fetch.load_local_rockspec("missing_mandatory_field-1.0-1.rockspec")) |
208 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/unknown_field-1.0-1.rockspec")) | 244 | assert.falsy(fetch.load_local_rockspec("unknown_field-1.0-1.rockspec")) |
209 | end) | 245 | end) |
210 | 246 | ||
211 | it("returns a table representing the rockspec from the given file", function() | 247 | it("returns a table representing the rockspec from the given file", function() |
@@ -222,24 +258,47 @@ describe("Luarocks fetch test #unit #mock", function() | |||
222 | end) | 258 | end) |
223 | 259 | ||
224 | it("returns false if the rockspec version is not supported", function() | 260 | it("returns false if the rockspec version is not supported", function() |
225 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/invalid_version.rockspec")) | 261 | assert.falsy(fetch.load_local_rockspec("invalid_version.rockspec")) |
226 | end) | 262 | end) |
227 | 263 | ||
228 | it("returns false if the rockspec doesn't pass the type checking", function() | 264 | it("returns false if the rockspec doesn't pass the type checking", function() |
229 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/type_mismatch_string-1.0-1.rockspec")) | 265 | write_file("type_mismatch_string-1.0-1.rockspec", [[ |
266 | package="type_mismatch_version" | ||
267 | version=1.0 | ||
268 | ]], finally) | ||
269 | assert.falsy(fetch.load_local_rockspec("type_mismatch_string-1.0-1.rockspec")) | ||
230 | end) | 270 | end) |
231 | 271 | ||
232 | it("returns false if the rockspec file name is not right", function() | 272 | it("returns false if the rockspec file name is not right", function() |
233 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/invalid_rockspec_name.rockspec")) | 273 | write_file("invalid_rockspec_name.rockspec", [[ |
274 | package="invalid_rockspec_name" | ||
275 | version="1.0-1" | ||
276 | source = { | ||
277 | url = "http://example.com/foo.tar.gz" | ||
278 | } | ||
279 | build = { | ||
280 | |||
281 | } | ||
282 | ]], finally) | ||
283 | assert.falsy(fetch.load_local_rockspec("invalid_rockspec_name.rockspec")) | ||
234 | end) | 284 | end) |
235 | 285 | ||
236 | it("returns false if the version in the rockspec file name doesn't match the version declared in the rockspec", function() | 286 | it("returns false if the version in the rockspec file name doesn't match the version declared in the rockspec", function() |
237 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/inconsistent_versions-1.0-1.rockspec")) | 287 | write_file("inconsistent_versions-1.0-1.rockspec", [[ |
288 | package="inconsistent_versions" | ||
289 | version="1.0-2" | ||
290 | source = { | ||
291 | url = "http://example.com/foo.tar.gz" | ||
292 | } | ||
293 | build = { | ||
294 | |||
295 | } | ||
296 | ]], finally) | ||
297 | assert.falsy(fetch.load_local_rockspec("inconsistent_versions-1.0-1.rockspec")) | ||
238 | end) | 298 | end) |
239 | end) | 299 | end) |
240 | 300 | ||
241 | describe("fetch.load_rockspec", function() | 301 | describe("fetch.load_rockspec", function() |
242 | |||
243 | it("returns a table containing the requested rockspec by downloading it into a temporary directory", function() | 302 | it("returns a table containing the requested rockspec by downloading it into a temporary directory", function() |
244 | path.use_tree(testing_paths.testing_tree) | 303 | path.use_tree(testing_paths.testing_tree) |
245 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec") | 304 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec") |
@@ -279,6 +338,25 @@ describe("Luarocks fetch test #unit #mock", function() | |||
279 | end) | 338 | end) |
280 | 339 | ||
281 | describe("fetch.get_sources", function() | 340 | describe("fetch.get_sources", function() |
341 | local tmpdir | ||
342 | local olddir | ||
343 | |||
344 | before_each(function() | ||
345 | tmpdir = get_tmp_path() | ||
346 | olddir = lfs.currentdir() | ||
347 | lfs.mkdir(tmpdir) | ||
348 | lfs.chdir(tmpdir) | ||
349 | fs.change_dir(tmpdir) | ||
350 | end) | ||
351 | |||
352 | after_each(function() | ||
353 | if olddir then | ||
354 | lfs.chdir(olddir) | ||
355 | if tmpdir then | ||
356 | lfs.rmdir(tmpdir) | ||
357 | end | ||
358 | end | ||
359 | end) | ||
282 | 360 | ||
283 | it("downloads the sources for building a rock and returns the resulting source filename and its parent directory", function() | 361 | it("downloads the sources for building a rock and returns the resulting source filename and its parent directory", function() |
284 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | 362 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) |
@@ -311,12 +389,33 @@ describe("Luarocks fetch test #unit #mock", function() | |||
311 | end) | 389 | end) |
312 | 390 | ||
313 | it("returns false and does nothing if the rockspec source url is invalid", function() | 391 | it("returns false and does nothing if the rockspec source url is invalid", function() |
314 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/invalid_url-1.0-1.rockspec")) | 392 | write_file("invalid_url-1.0-1.rockspec", [[ |
393 | package="invalid_url" | ||
394 | version="1.0-1" | ||
395 | source = { | ||
396 | url = "http://localhost:8080/file/nonexistent" | ||
397 | } | ||
398 | build = { | ||
399 | |||
400 | } | ||
401 | ]], finally) | ||
402 | local rockspec = assert(fetch.load_rockspec("invalid_url-1.0-1.rockspec")) | ||
315 | assert.falsy(fetch.get_sources(rockspec, false)) | 403 | assert.falsy(fetch.get_sources(rockspec, false)) |
316 | end) | 404 | end) |
317 | 405 | ||
318 | it("returns false and does nothing if the downloaded rockspec has an invalid md5 checksum", function() | 406 | it("returns false and does nothing if the downloaded rockspec has an invalid md5 checksum", function() |
319 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/invalid_checksum-1.0-1.rockspec")) | 407 | write_file("invalid_checksum-1.0-1.rockspec", [[ |
408 | package="invalid_checksum" | ||
409 | version="1.0-1" | ||
410 | source = { | ||
411 | url = "http://localhost:8080/file/a_rock.lua", | ||
412 | md5 = "invalid" | ||
413 | } | ||
414 | build = { | ||
415 | |||
416 | } | ||
417 | ]], finally) | ||
418 | local rockspec = assert(fetch.load_rockspec("invalid_checksum-1.0-1.rockspec")) | ||
320 | assert.falsy(fetch.get_sources(rockspec, false)) | 419 | assert.falsy(fetch.get_sources(rockspec, false)) |
321 | end) | 420 | end) |
322 | end) | 421 | end) |