diff options
| -rw-r--r-- | spec/fetch_spec.lua | 358 | ||||
| -rw-r--r-- | spec/fixtures/a_rock-1.0-1.src.rock | bin | 0 -> 446 bytes | |||
| -rw-r--r-- | spec/fixtures/inconsistent_versions-1.0-1.rockspec | 8 | ||||
| -rw-r--r-- | spec/fixtures/invalid_checksum-1.0-1.rockspec | 9 | ||||
| -rw-r--r-- | spec/fixtures/invalid_rockspec_name.rockspec | 8 | ||||
| -rw-r--r-- | spec/fixtures/invalid_rockspec_version-1.0-1.rockspec | 9 | ||||
| -rw-r--r-- | spec/fixtures/invalid_url-1.0-1.rockspec | 8 | ||||
| -rw-r--r-- | spec/fixtures/missing_mandatory_field-1.0-1.rockspec | 5 | ||||
| -rw-r--r-- | spec/fixtures/unknown_field-1.0-1.rockspec | 6 |
9 files changed, 409 insertions, 2 deletions
diff --git a/spec/fetch_spec.lua b/spec/fetch_spec.lua index 79b160c1..c98a3de3 100644 --- a/spec/fetch_spec.lua +++ b/spec/fetch_spec.lua | |||
| @@ -3,9 +3,212 @@ local git_repo = require("spec.util.git_repo") | |||
| 3 | 3 | ||
| 4 | test_env.unload_luarocks() | 4 | test_env.unload_luarocks() |
| 5 | local fetch = require("luarocks.fetch") | 5 | local fetch = require("luarocks.fetch") |
| 6 | local path = require("luarocks.path") | ||
| 7 | local lfs = require("lfs") | ||
| 8 | local testing_paths = test_env.testing_paths | ||
| 9 | local get_tmp_path = test_env.get_tmp_path | ||
| 6 | 10 | ||
| 7 | describe("Luarocks fetch test #whitebox #w_fetch", function() | 11 | describe("Luarocks fetch test #blackbox #b_fetch", function() |
| 8 | it("Fetch url to base dir", function() | 12 | local are_same_files = function(file1, file2) |
| 13 | return file1 == file2 or lfs.attributes(file1).ino == lfs.attributes(file2).ino | ||
| 14 | end | ||
| 15 | |||
| 16 | |||
| 17 | describe("fetch.is_basic_protocol", function() | ||
| 18 | it("checks whether the arguments represent a valid protocol and returns the result of the check", function() | ||
| 19 | assert.truthy(fetch.is_basic_protocol("http")) | ||
| 20 | assert.truthy(fetch.is_basic_protocol("https")) | ||
| 21 | assert.truthy(fetch.is_basic_protocol("ftp")) | ||
| 22 | assert.truthy(fetch.is_basic_protocol("file")) | ||
| 23 | assert.falsy(fetch.is_basic_protocol("file", true)) | ||
| 24 | assert.falsy(fetch.is_basic_protocol("invalid")) | ||
| 25 | end) | ||
| 26 | end) | ||
| 27 | |||
| 28 | describe("fetch.fetch_url", function() | ||
| 29 | setup(function() | ||
| 30 | test_env.mock_server_init() | ||
| 31 | end) | ||
| 32 | |||
| 33 | teardown(function() | ||
| 34 | test_env.mock_server_done() | ||
| 35 | end) | ||
| 36 | |||
| 37 | it("fetches the url argument and returns the absolute path of the fetched file", function() | ||
| 38 | local fetchedfile = fetch.fetch_url("http://localhost:8080/file/a_rock.lua") | ||
| 39 | assert.truthy(are_same_files(fetchedfile, lfs.currentdir() .. "/a_rock.lua")) | ||
| 40 | local fd = assert(io.open(fetchedfile, "r")) | ||
| 41 | local fetchedcontent = assert(fd:read("*a")) | ||
| 42 | fd:close() | ||
| 43 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | ||
| 44 | local filecontent = assert(fd:read("*a")) | ||
| 45 | fd:close() | ||
| 46 | assert.same(fetchedcontent, filecontent) | ||
| 47 | os.remove(fetchedfile) | ||
| 48 | end) | ||
| 49 | |||
| 50 | it("returns the absolute path of the filename argument if the url represents a file", function() | ||
| 51 | local file = fetch.fetch_url("file://a_rock.lua") | ||
| 52 | assert.truthy(are_same_files(file, lfs.currentdir() .. "/a_rock.lua")) | ||
| 53 | end) | ||
| 54 | |||
| 55 | it("returns false and does nothing if the url argument contains a nonexistent file", function() | ||
| 56 | assert.falsy(fetch.fetch_url("http://localhost:8080/file/nonexistent")) | ||
| 57 | end) | ||
| 58 | |||
| 59 | it("returns false and does nothing if the url argument is invalid", function() | ||
| 60 | assert.falsy(fetch.fetch_url("invalid://url", "file")) | ||
| 61 | end) | ||
| 62 | end) | ||
| 63 | |||
| 64 | describe("fetch.fetch_url_at_temp_dir", function() | ||
| 65 | local tmpfile | ||
| 66 | local tmpdir | ||
| 67 | |||
| 68 | after_each(function() | ||
| 69 | if tmpfile then | ||
| 70 | os.remove(tmpfile) | ||
| 71 | tmpfile = nil | ||
| 72 | end | ||
| 73 | if tmpdir then | ||
| 74 | lfs.rmdir(tmpdir) | ||
| 75 | tmpdir = nil | ||
| 76 | end | ||
| 77 | end) | ||
| 78 | |||
| 79 | setup(function() | ||
| 80 | test_env.mock_server_init() | ||
| 81 | end) | ||
| 82 | |||
| 83 | teardown(function() | ||
| 84 | test_env.mock_server_done() | ||
| 85 | end) | ||
| 86 | |||
| 87 | it("returns the absolute path and the parent directory of the file specified by the url", function() | ||
| 88 | tmpdir = get_tmp_path() | ||
| 89 | lfs.mkdir(tmpdir) | ||
| 90 | tmpfile = tmpdir .. "/tmpfile" | ||
| 91 | local fd = assert(io.open(tmpfile, "w")) | ||
| 92 | local pathname, dirname = fetch.fetch_url_at_temp_dir("file://" .. tmpfile, "test") | ||
| 93 | assert.truthy(are_same_files(tmpfile, pathname)) | ||
| 94 | assert.truthy(are_same_files(tmpdir, dirname)) | ||
| 95 | end) | ||
| 96 | |||
| 97 | it("returns true and fetches the url into a temporary dir", function() | ||
| 98 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test") | ||
| 99 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/a_rock.lua")) | ||
| 100 | local fd = assert(io.open(fetchedfile, "r")) | ||
| 101 | local fetchedcontent = assert(fd:read("*a")) | ||
| 102 | fd:close() | ||
| 103 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | ||
| 104 | local filecontent = assert(fd:read("*a")) | ||
| 105 | fd:close() | ||
| 106 | assert.same(fetchedcontent, filecontent) | ||
| 107 | end) | ||
| 108 | |||
| 109 | it("returns true and fetches the url into a temporary dir with custom filename", function() | ||
| 110 | local fetchedfile, tmpdir = fetch.fetch_url_at_temp_dir("http://localhost:8080/file/a_rock.lua", "test", "my_a_rock.lua") | ||
| 111 | assert.truthy(are_same_files(fetchedfile, tmpdir .. "/my_a_rock.lua")) | ||
| 112 | assert.truthy(string.find(tmpdir, "test")) | ||
| 113 | local fd = assert(io.open(fetchedfile, "r")) | ||
| 114 | local fetchedcontent = assert(fd:read("*a")) | ||
| 115 | fd:close() | ||
| 116 | fd = assert(io.open(testing_paths.fixtures_dir .. "/a_rock.lua", "r")) | ||
| 117 | local filecontent = assert(fd:read("*a")) | ||
| 118 | fd:close() | ||
| 119 | assert.same(fetchedcontent, filecontent) | ||
| 120 | end) | ||
| 121 | |||
| 122 | it("returns false and does nothing if the file specified in the url is nonexistent", function() | ||
| 123 | assert.falsy(fetch.fetch_url_at_temp_dir("file://nonexistent", "test")) | ||
| 124 | assert.falsy(fetch.fetch_url_at_temp_dir("http://localhost:8080/file/nonexistent", "test")) | ||
| 125 | end) | ||
| 126 | |||
| 127 | it("returns false and does nothing if the url is invalid", function() | ||
| 128 | assert.falsy(fetch.fetch_url_at_temp_dir("url://invalid", "test")) | ||
| 129 | end) | ||
| 130 | end) | ||
| 131 | |||
| 132 | describe("fetch.find_base_dir", function() | ||
| 133 | setup(function() | ||
| 134 | test_env.mock_server_init() | ||
| 135 | end) | ||
| 136 | |||
| 137 | teardown(function() | ||
| 138 | test_env.mock_server_done() | ||
| 139 | end) | ||
| 140 | |||
| 141 | it("extracts the archive given by the file argument and returns the inferred and the actual root directory in the archive", function() | ||
| 142 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" | ||
| 143 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) | ||
| 144 | local inferreddir, founddir = fetch.find_base_dir(file, tmpdir, url) | ||
| 145 | assert.truthy(are_same_files(inferreddir, founddir)) | ||
| 146 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) | ||
| 147 | end) | ||
| 148 | |||
| 149 | it("extracts the archive given by the file argument with given base directory and returns the inferred and the actual root directory in the archive", function() | ||
| 150 | local url = "http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz" | ||
| 151 | local file, tmpdir = assert(fetch.fetch_url_at_temp_dir(url, "test")) | ||
| 152 | local inferreddir, founddir = fetch.find_base_dir(file, tmpdir, url, "basedir") | ||
| 153 | assert.truthy(are_same_files(inferreddir, "basedir")) | ||
| 154 | assert.truthy(are_same_files(founddir, "an_upstream_tarball-0.1")) | ||
| 155 | assert.truthy(lfs.attributes(tmpdir .. "/" .. founddir)) | ||
| 156 | end) | ||
| 157 | |||
| 158 | it("returns false and does nothing if the temporary directory doesn't exist", function() | ||
| 159 | assert.falsy(fetch.find_base_dir("file", "nonexistent", "url")) | ||
| 160 | end) | ||
| 161 | end) | ||
| 162 | |||
| 163 | describe("fetch.fetch_and_unpack_rock", function() | ||
| 164 | local tmpdir | ||
| 165 | |||
| 166 | after_each(function() | ||
| 167 | if tmpdir then | ||
| 168 | lfs.rmdir(tmpdir) | ||
| 169 | tmpdir = nil | ||
| 170 | end | ||
| 171 | end) | ||
| 172 | |||
| 173 | setup(function() | ||
| 174 | test_env.mock_server_init() | ||
| 175 | end) | ||
| 176 | |||
| 177 | teardown(function() | ||
| 178 | test_env.mock_server_done() | ||
| 179 | end) | ||
| 180 | |||
| 181 | it("unpacks the rock file from the url and returns its resulting temporary parent directory", function() | ||
| 182 | tmpdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock") | ||
| 183 | assert.truthy(string.find(tmpdir, "a_rock%-1%.0%-1")) | ||
| 184 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) | ||
| 185 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock.lua")) | ||
| 186 | end) | ||
| 187 | |||
| 188 | it("unpacks the rock file from the url with custom unpacking directory", function() | ||
| 189 | tmpdir = get_tmp_path() | ||
| 190 | lfs.mkdir(tmpdir) | ||
| 191 | local resultingdir = fetch.fetch_and_unpack_rock("http://localhost:8080/file/a_rock-1.0-1.src.rock", tmpdir) | ||
| 192 | assert.truthy(are_same_files(resultingdir, tmpdir)) | ||
| 193 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock-1.0-1.rockspec")) | ||
| 194 | assert.truthy(lfs.attributes(resultingdir .. "/a_rock.lua")) | ||
| 195 | end) | ||
| 196 | |||
| 197 | it("does nothing if the url doesn't represent a rock file", function() | ||
| 198 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "http://localhost:8080/file/a_rock.lua")) | ||
| 199 | end) | ||
| 200 | |||
| 201 | it("does nothing if the rock file url is invalid", function() | ||
| 202 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "url://invalid")) | ||
| 203 | end) | ||
| 204 | |||
| 205 | it("does nothing if the rock file url represents a nonexistent file", function() | ||
| 206 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "url://invalid")) | ||
| 207 | assert.falsy(pcall(fetch.fetch_and_unpack_rock, "http://localhost:8080/file/nonexistent")) | ||
| 208 | end) | ||
| 209 | end) | ||
| 210 | |||
| 211 | describe("fetch.url_to_base_dir", function() | ||
| 9 | assert.are.same("v0.3", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) | 212 | assert.are.same("v0.3", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2/archive/v0.3.zip")) |
| 10 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2.zip")) | 213 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2.zip")) |
| 11 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2.tar.gz")) | 214 | assert.are.same("lua-compat-5.2", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2.tar.gz")) |
| @@ -13,6 +216,157 @@ describe("Luarocks fetch test #whitebox #w_fetch", function() | |||
| 13 | assert.are.same("parser.moon", fetch.url_to_base_dir("git://example.com/Cirru/parser.moon")) | 216 | assert.are.same("parser.moon", fetch.url_to_base_dir("git://example.com/Cirru/parser.moon")) |
| 14 | assert.are.same("v0.3", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2/archive/v0.3")) | 217 | assert.are.same("v0.3", fetch.url_to_base_dir("https://example.com/hishamhm/lua-compat-5.2/archive/v0.3")) |
| 15 | end) | 218 | end) |
| 219 | |||
| 220 | describe("fetch.load_local_rockspec", function() | ||
| 221 | it("returns a table representing the rockspec from the given file skipping some checks if the quick argument is enabled", function() | ||
| 222 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec", true) | ||
| 223 | assert.same(rockspec.name, "a_rock") | ||
| 224 | assert.same(rockspec.version, "1.0-1") | ||
| 225 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | ||
| 226 | assert.same(rockspec.description, { summary = "An example rockspec" }) | ||
| 227 | |||
| 228 | rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/missing_mandatory_field-1.0-1.rockspec", true) | ||
| 229 | assert.same(rockspec.name, "missing_mandatory_field") | ||
| 230 | assert.same(rockspec.version, "1.0-1") | ||
| 231 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | ||
| 232 | |||
| 233 | rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/unknown_field-1.0-1.rockspec", true) | ||
| 234 | assert.same(rockspec.name, "unknown_field") | ||
| 235 | assert.same(rockspec.version, "1.0-1") | ||
| 236 | assert.same(rockspec.source.url, "http://example.com/foo.tar.gz") | ||
| 237 | |||
| 238 | -- The previous calls fail if the detailed checking is done | ||
| 239 | assert.falsy(pcall(fetch.load_local_rockspec, testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec")) | ||
| 240 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/missing_mandatory_field-1.0-1.rockspec")) | ||
| 241 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/unknown_field-1.0-1.rockspec")) | ||
| 242 | end) | ||
| 243 | |||
| 244 | it("returns a table representing the rockspec from the given file", function() | ||
| 245 | path.use_tree(testing_paths.testing_tree) | ||
| 246 | local rockspec = fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec") | ||
| 247 | assert.same(rockspec.name, "a_rock") | ||
| 248 | assert.same(rockspec.version, "1.0-1") | ||
| 249 | assert.same(rockspec.description, { summary = "An example rockspec" }) | ||
| 250 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | ||
| 251 | end) | ||
| 252 | |||
| 253 | it("returns false if the rockspec in invalid", function() | ||
| 254 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/invalid_validate-args-1.5.4-1.rockspec")) | ||
| 255 | end) | ||
| 256 | |||
| 257 | it("returns false if the rockspec version is not supported", function() | ||
| 258 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/invalid_version.rockspec")) | ||
| 259 | end) | ||
| 260 | |||
| 261 | it("returns false if the rockspec doesn't pass the type checking", function() | ||
| 262 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/type_mismatch_string-1.0-1.rockspec")) | ||
| 263 | end) | ||
| 264 | |||
| 265 | it("returns false if the rockspec file name is not right", function() | ||
| 266 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/invalid_rockspec_name.rockspec")) | ||
| 267 | end) | ||
| 268 | |||
| 269 | it("returns false if the version in the rockspec file name doesn't match the version declared in the rockspec", function() | ||
| 270 | assert.falsy(fetch.load_local_rockspec(testing_paths.fixtures_dir .. "/inconsistent_versions-1.0-1.rockspec")) | ||
| 271 | end) | ||
| 272 | end) | ||
| 273 | |||
| 274 | describe("fetch.load_rockspec", function() | ||
| 275 | setup(function() | ||
| 276 | test_env.mock_server_init() | ||
| 277 | end) | ||
| 278 | |||
| 279 | teardown(function() | ||
| 280 | test_env.mock_server_done() | ||
| 281 | end) | ||
| 282 | |||
| 283 | it("returns a table containing the requested rockspec by downloading it into a temporary directory", function() | ||
| 284 | path.use_tree(testing_paths.testing_tree) | ||
| 285 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec") | ||
| 286 | assert.same(rockspec.name, "a_rock") | ||
| 287 | assert.same(rockspec.version, "1.0-1") | ||
| 288 | assert.same(rockspec.description, { summary = "An example rockspec" }) | ||
| 289 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | ||
| 290 | rockspec = fetch.load_rockspec(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec") | ||
| 291 | assert.same(rockspec.name, "a_rock") | ||
| 292 | assert.same(rockspec.version, "1.0-1") | ||
| 293 | assert.same(rockspec.description, { summary = "An example rockspec" }) | ||
| 294 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | ||
| 295 | end) | ||
| 296 | |||
| 297 | it("returns a table containing the requested rockspec by downloading it into a given directory", function() | ||
| 298 | local tmpdir = get_tmp_path() | ||
| 299 | lfs.mkdir(tmpdir) | ||
| 300 | |||
| 301 | path.use_tree(testing_paths.testing_tree) | ||
| 302 | local rockspec = fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec", tmpdir) | ||
| 303 | assert.same(rockspec.name, "a_rock") | ||
| 304 | assert.same(rockspec.version, "1.0-1") | ||
| 305 | assert.same(rockspec.description, { summary = "An example rockspec" }) | ||
| 306 | assert.same(rockspec.source.url, "http://localhost:8080/file/a_rock.lua") | ||
| 307 | assert.truthy(lfs.attributes(tmpdir .. "/a_rock-1.0-1.rockspec")) | ||
| 308 | |||
| 309 | lfs.rmdir(tmpdir) | ||
| 310 | end) | ||
| 311 | |||
| 312 | it("returns false if the given download directory doesn't exist", function() | ||
| 313 | assert.falsy(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec", "nonexistent")) | ||
| 314 | end) | ||
| 315 | |||
| 316 | it("returns false if the given filename is not a valid rockspec name", function() | ||
| 317 | assert.falsy(fetch.load_rockspec("http://localhost:8080/file/a_rock.lua")) | ||
| 318 | end) | ||
| 319 | end) | ||
| 320 | |||
| 321 | describe("fetch.get_sources", function() | ||
| 322 | setup(function() | ||
| 323 | test_env.mock_server_init() | ||
| 324 | end) | ||
| 325 | |||
| 326 | teardown(function() | ||
| 327 | test_env.mock_server_done() | ||
| 328 | end) | ||
| 329 | |||
| 330 | it("downloads the sources for building a rock and returns the resulting source filename and its parent directory", function() | ||
| 331 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | ||
| 332 | local file, dir = fetch.get_sources(rockspec, false) | ||
| 333 | assert.truthy(are_same_files(dir .. "/a_rock.lua", file)) | ||
| 334 | end) | ||
| 335 | |||
| 336 | it("downloads the sources for building a rock into a given directory and returns the resulting source filename and its parent directory", function() | ||
| 337 | local tmpdir = get_tmp_path() | ||
| 338 | lfs.mkdir(tmpdir) | ||
| 339 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | ||
| 340 | local file, dir = fetch.get_sources(rockspec, false, tmpdir) | ||
| 341 | assert.truthy(are_same_files(tmpdir, dir)) | ||
| 342 | assert.truthy(are_same_files(dir .. "/a_rock.lua", file)) | ||
| 343 | lfs.rmdir(tmpdir) | ||
| 344 | end) | ||
| 345 | |||
| 346 | it("downloads the sources for building a rock, extracts the downloaded tarball and returns the resulting source filename and its parent directory", function() | ||
| 347 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/busted_project-0.1-1.rockspec")) | ||
| 348 | local file, dir = fetch.get_sources(rockspec, true) | ||
| 349 | assert.truthy(are_same_files(dir .. "/busted_project-0.1.tar.gz", file)) | ||
| 350 | assert.truthy(lfs.attributes(dir .. "/busted_project")) | ||
| 351 | assert.truthy(lfs.attributes(dir .. "/busted_project/sum.lua")) | ||
| 352 | assert.truthy(lfs.attributes(dir .. "/busted_project/spec/sum_spec.lua")) | ||
| 353 | end) | ||
| 354 | |||
| 355 | it("returns false and does nothing if the destination directory doesn't exist", function() | ||
| 356 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/a_rock-1.0-1.rockspec")) | ||
| 357 | assert.falsy(fetch.get_sources(rockspec, false, "nonexistent")) | ||
| 358 | end) | ||
| 359 | |||
| 360 | it("returns false and does nothing if the rockspec source url is invalid", function() | ||
| 361 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/invalid_url-1.0-1.rockspec")) | ||
| 362 | assert.falsy(fetch.get_sources(rockspec, false)) | ||
| 363 | end) | ||
| 364 | |||
| 365 | it("returns false and does nothing if the downloaded rockspec has an invalid md5 checksum", function() | ||
| 366 | local rockspec = assert(fetch.load_rockspec("http://localhost:8080/file/invalid_checksum-1.0-1.rockspec")) | ||
| 367 | assert.falsy(fetch.get_sources(rockspec, false)) | ||
| 368 | end) | ||
| 369 | end) | ||
| 16 | 370 | ||
| 17 | describe("fetch_sources #unix #git", function() | 371 | describe("fetch_sources #unix #git", function() |
| 18 | local git | 372 | local git |
diff --git a/spec/fixtures/a_rock-1.0-1.src.rock b/spec/fixtures/a_rock-1.0-1.src.rock new file mode 100644 index 00000000..9d0bb455 --- /dev/null +++ b/spec/fixtures/a_rock-1.0-1.src.rock | |||
| Binary files differ | |||
diff --git a/spec/fixtures/inconsistent_versions-1.0-1.rockspec b/spec/fixtures/inconsistent_versions-1.0-1.rockspec new file mode 100644 index 00000000..c8c1eee2 --- /dev/null +++ b/spec/fixtures/inconsistent_versions-1.0-1.rockspec | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | package="inconsistent_versions" | ||
| 2 | version="1.0-2" | ||
| 3 | source = { | ||
| 4 | url = "http://example.com/foo.tar.gz" | ||
| 5 | } | ||
| 6 | build = { | ||
| 7 | |||
| 8 | } | ||
diff --git a/spec/fixtures/invalid_checksum-1.0-1.rockspec b/spec/fixtures/invalid_checksum-1.0-1.rockspec new file mode 100644 index 00000000..256cb1fe --- /dev/null +++ b/spec/fixtures/invalid_checksum-1.0-1.rockspec | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | package="invalid_checksum" | ||
| 2 | version="1.0-1" | ||
| 3 | source = { | ||
| 4 | url = "http://localhost:8080/file/a_rock.lua", | ||
| 5 | md5 = "invalid" | ||
| 6 | } | ||
| 7 | build = { | ||
| 8 | |||
| 9 | } | ||
diff --git a/spec/fixtures/invalid_rockspec_name.rockspec b/spec/fixtures/invalid_rockspec_name.rockspec new file mode 100644 index 00000000..ab70c75d --- /dev/null +++ b/spec/fixtures/invalid_rockspec_name.rockspec | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | package="invalid_rockspec_name" | ||
| 2 | version="1.0-1" | ||
| 3 | source = { | ||
| 4 | url = "http://example.com/foo.tar.gz" | ||
| 5 | } | ||
| 6 | build = { | ||
| 7 | |||
| 8 | } | ||
diff --git a/spec/fixtures/invalid_rockspec_version-1.0-1.rockspec b/spec/fixtures/invalid_rockspec_version-1.0-1.rockspec new file mode 100644 index 00000000..f644b3d9 --- /dev/null +++ b/spec/fixtures/invalid_rockspec_version-1.0-1.rockspec | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | rockspec_format="3.1" | ||
| 2 | package="invalid_rockspec_version" | ||
| 3 | version="1.0-1" | ||
| 4 | source = { | ||
| 5 | url = "http://example.com/foo.tar.gz" | ||
| 6 | } | ||
| 7 | build = { | ||
| 8 | |||
| 9 | } | ||
diff --git a/spec/fixtures/invalid_url-1.0-1.rockspec b/spec/fixtures/invalid_url-1.0-1.rockspec new file mode 100644 index 00000000..a74b0281 --- /dev/null +++ b/spec/fixtures/invalid_url-1.0-1.rockspec | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | package="invalid_url" | ||
| 2 | version="1.0-1" | ||
| 3 | source = { | ||
| 4 | url = "http://localhost:8080/file/nonexistent" | ||
| 5 | } | ||
| 6 | build = { | ||
| 7 | |||
| 8 | } | ||
diff --git a/spec/fixtures/missing_mandatory_field-1.0-1.rockspec b/spec/fixtures/missing_mandatory_field-1.0-1.rockspec new file mode 100644 index 00000000..56dac987 --- /dev/null +++ b/spec/fixtures/missing_mandatory_field-1.0-1.rockspec | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | package="missing_mandatory_field" | ||
| 2 | version="1.0-1" | ||
| 3 | source = { | ||
| 4 | url = "http://example.com/foo.tar.gz" | ||
| 5 | } | ||
diff --git a/spec/fixtures/unknown_field-1.0-1.rockspec b/spec/fixtures/unknown_field-1.0-1.rockspec new file mode 100644 index 00000000..bcad2d53 --- /dev/null +++ b/spec/fixtures/unknown_field-1.0-1.rockspec | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | package="unknown_field" | ||
| 2 | version="1.0-1" | ||
| 3 | source = { | ||
| 4 | url = "http://example.com/foo.tar.gz" | ||
| 5 | } | ||
| 6 | unknown="foo" | ||
