From 2dc0a68c941d883753b2d6715921a8952f95204b Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Fri, 30 Mar 2018 15:22:09 -0300 Subject: Tests: run our own local git-daemon repository for git tests --- spec/write_rockspec_spec.lua | 107 ++++++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 38 deletions(-) (limited to 'spec/write_rockspec_spec.lua') diff --git a/spec/write_rockspec_spec.lua b/spec/write_rockspec_spec.lua index 9ee86ada..e4a7fa73 100644 --- a/spec/write_rockspec_spec.lua +++ b/spec/write_rockspec_spec.lua @@ -1,8 +1,9 @@ local test_env = require("spec.util.test_env") +local git_repo = require("spec.util.git_repo") local lfs = require("lfs") local run = test_env.run -test_env.unload_luarocks() +local extra_rocks = test_env.mock_server_extra_rocks() describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() @@ -10,63 +11,93 @@ describe("LuaRocks write_rockspec tests #blackbox #b_write_rockspec", function() test_env.setup_specs() end) - describe("LuaRocks write_rockspec basic tests", function() - it("LuaRocks write_rockspec with no flags/arguments", function() - assert.is_true(run.luarocks_bool("write_rockspec")) - os.remove("luarocks-dev-1.rockspec") + it("runs with no flags/arguments", function() + local d = lfs.currentdir() + finally(function() + os.remove("testrock-dev-1.rockspec") + lfs.chdir(d) end) + lfs.chdir("..") + assert.is_true(run.luarocks_bool("write_rockspec")) + end) - it("LuaRocks write_rockspec with invalid argument", function() - assert.is_false(run.luarocks_bool("write_rockspec invalid")) + it("fails with invalid argument", function() + assert.is_false(run.luarocks_bool("write_rockspec invalid")) + end) + + it("fails with invalid zip", function() + assert.is_false(run.luarocks_bool("write_rockspec http://example.com/invalid.zip")) + end) + + describe("from #git #unix", function() + local git + + setup(function() + git = git_repo.start() end) - it("LuaRocks write_rockspec invalid zip", function() - assert.is_false(run.luarocks_bool("write_rockspec http://example.com/invalid.zip")) + teardown(function() + git:stop() end) - end) - describe("LuaRocks write_rockspec more complex tests", function() - it("LuaRocks write_rockspec git luarocks", function() - assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock")) + it("runs", function() + finally(function() os.remove("testrock-dev-1.rockspec") end) + assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock")) assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) - assert.is_true(os.remove("testrock-dev-1.rockspec")) end) - it("LuaRocks write_rockspec git luarocks --tag=v2.3.0", function() - assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --tag=v2.3.0")) + it("runs with --tag", function() + finally(function() os.remove("testrock-2.3.0-1.rockspec") end) + assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock --tag=v2.3.0")) assert.is.truthy(lfs.attributes("testrock-2.3.0-1.rockspec")) - assert.is_true(os.remove("testrock-2.3.0-1.rockspec")) + -- TODO check contents end) - it("LuaRocks write_rockspec git luarocks with format flag", function() - assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --rockspec-format=1.1 --lua-version=5.1,5.2")) + it("runs with format flag", function() + finally(function() os.remove("testrock-dev-1.rockspec") end) + assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock --rockspec-format=1.1 --lua-version=5.1,5.2")) assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) - assert.is_true(os.remove("testrock-dev-1.rockspec")) + -- TODO check contents end) - it("LuaRocks write_rockspec git luarocks with full flags", function() - assert.is_true(run.luarocks_bool("write_rockspec git://github.com/luarocks/testrock --lua-version=5.1,5.2 --license=\"MIT/X11\" " + it("runs with full flags", function() + finally(function() os.remove("testrock-dev-1.rockspec") end) + assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock --lua-version=5.1,5.2 --license=\"MIT/X11\" " .. " --homepage=\"http://www.luarocks.org\" --summary=\"A package manager for Lua modules\" ")) assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) - assert.is_true(os.remove("testrock-dev-1.rockspec")) + -- TODO check contents end) - - it("LuaRocks write_rockspec rockspec via http", function() - assert.is_true(run.luarocks_bool("write_rockspec http://luarocks.org/releases/luarocks-2.1.0.tar.gz --lua-version=5.1")) - assert.is.truthy(lfs.attributes("luarocks-2.1.0-1.rockspec")) - assert.is_true(os.remove("luarocks-2.1.0-1.rockspec")) + + it("with various flags", function() + finally(function() os.remove("testrock-dev-1.rockspec") end) + assert.is_true(run.luarocks_bool("write_rockspec git://localhost:20000/testrock --lib=fcgi --license=\"3-clause BSD\" " .. "--lua-version=5.1,5.2")) + assert.is.truthy(lfs.attributes("testrock-dev-1.rockspec")) + -- TODO check contents end) - - it("LuaRocks write_rockspec base dir, luassert.tar.gz via https", function() - assert.is_true(run.luarocks_bool("write_rockspec https://github.com/downloads/Olivine-Labs/luassert/luassert-1.2.tar.gz --lua-version=5.1")) - assert.is.truthy(lfs.attributes("luassert-1.2-1.rockspec")) - assert.is_true(os.remove("luassert-1.2-1.rockspec")) + end) + + describe("from tarball #mock", function() + + setup(function() + test_env.setup_specs(extra_rocks) + test_env.mock_server_init() end) - - it("LuaRocks write_rockspec git luafcgi with many flags", function() - assert.is_true(run.luarocks_bool("write_rockspec git://github.com/arcapos/luafcgi --lib=fcgi --license=\"3-clause BSD\" " .. "--lua-version=5.1,5.2")) - assert.is.truthy(lfs.attributes("luafcgi-dev-1.rockspec")) -- TODO maybe read it content and find arguments from flags? - assert.is_true(os.remove("luafcgi-dev-1.rockspec")) + teardown(function() + test_env.mock_server_done() + end) + + it("via http", function() + finally(function() os.remove("an_upstream_tarball-0.1-1.rockspec") end) + assert.is_true(run.luarocks_bool("write_rockspec http://localhost:8080/file/an_upstream_tarball-0.1.tar.gz --lua-version=5.1")) + assert.is.truthy(lfs.attributes("an_upstream_tarball-0.1-1.rockspec")) + -- TODO check contents + end) + + it("with a different basedir", function() + finally(function() os.remove("renamed_upstream_tarball-0.1-1.rockspec") end) + assert.is_true(run.luarocks_bool("write_rockspec http://localhost:8080/file/renamed_upstream_tarball-0.1.tar.gz --lua-version=5.1")) + assert.is.truthy(lfs.attributes("renamed_upstream_tarball-0.1-1.rockspec")) + -- TODO check contents end) end) end) -- cgit v1.2.3-55-g6feb