aboutsummaryrefslogtreecommitdiff
path: root/spec/upload_spec.lua
blob: 921a9fa4749929141d83a45b761f4e4d045a0fdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
local test_env = require("spec.util.test_env")
local run = test_env.run
local testing_paths = test_env.testing_paths

describe("luarocks upload #integration", function()

   describe("general tests", function()
      before_each(function()
         test_env.setup_specs(nil)
      end)

      it("with no flags/arguments", function()
         assert.is_false(run.luarocks_bool("upload"))
      end)

      it("invalid rockspec", function()
         assert.is_false(run.luarocks_bool("upload invalid.rockspec"))
      end)

      it("api key invalid", function()
         assert.is_false(run.luarocks_bool("upload --api-key=invalid invalid.rockspec"))
      end)

      it("api key invalid and skip-pack", function()
         assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --skip-pack " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.rockspec"))
      end)

      it("force #unix", function()
         assert.is_false(run.luarocks_bool("upload --api-key=\"invalid\" --force " .. testing_paths.testing_server .. "/luasocket-${LUASOCKET}.rockspec"))
      end)
   end)

   describe("tests with Xavante server #mock", function()
      lazy_setup(function()
         test_env.setup_specs(nil, "mock")
         test_env.mock_server_init()
      end)

      lazy_teardown(test_env.mock_server_done)

      it("rockspec with api-key", function()
         assert.is_true(run.luarocks_bool("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"}))
      end)

      it("#gpg rockspec with --sign", function()
         local function cleanup()
            os.remove(testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec.asc")
            os.remove(testing_paths.testrun_dir .. "/a_rock-1.0-1.src.rock.asc")
         end
         cleanup()
         finally(cleanup)
         print(run.luarocks("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123 --sign", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"}))
      end)

      it("with .rockspec and .src.rock", function()
         assert.is_true(run.luarocks_bool("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.src.rock " .. test_env.openssl_dirs, {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"}))
      end)

      it("with arguments .src.rock and .rockspec out of order", function()
         assert.is_false(run.luarocks_bool("upload " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.src.rock " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs, {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"}))
      end)

      it("rockspec with api-key and skip-pack", function()
         assert.is_true(run.luarocks_bool("upload --skip-pack " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"}))
      end)

      it("rockspec with api-key and dry-run", function()
         local output = run.luarocks("upload --dry-run " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})
         assert.truthy(output:find("would upload", 1, true))
         assert.truthy(output:find("Done: dry run", 1, true))
      end)

      it("rockspec with api-key, dry-run and skip-pack", function()
         local output = run.luarocks("upload --dry-run --skip-pack " .. testing_paths.fixtures_dir .. "/a_rock-1.0-1.rockspec " .. test_env.openssl_dirs .. " --api-key=123", {LUAROCKS_CONFIG = testing_paths.testrun_dir .. "/luarocks_site.lua"})
         assert.truthy(output:find("would upload", 1, true))
         assert.truthy(output:find("Done: dry run", 1, true))
         assert.falsy(output:find("%.src%.rock"))
      end)
   end)
end)