aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/fetch_spec.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-10-11 16:31:50 +0200
committerWilliam Boman <william@redwill.se>2025-02-19 09:22:40 +0100
commit047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc (patch)
treec50c22cd05d3605fc5a1e8eb902ffeb11e339697 /tests/mason-core/fetch_spec.lua
parentrefactor(receipt): change receipt structure and remove old builder APIs (#1521) (diff)
downloadmason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.gz
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.bz2
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.lz
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.xz
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.tar.zst
mason-047ec18da56ad8f331e5c6bc7417dc5a9a6e71cc.zip
refactor!: refactor installer internals and add new Package class methods (#1523)
This contains the following changes: 1) `Package:install()` now accepts a second, optional, callback argument which is called when installation finishes (successfully or not). 2) Adds a `Package:is_installing()` method. This contains the following breaking changes: 1) `Package:install()` will now error when called while an installation is already ongoing. Use the new `Package:is_installing()` method to check whether an installation is already running. This also refactors large portions of the tests by removing test globals, removing async_test, and adding the `mason-test` Lua module instead. Test helpers via globals are problematic to work with due to not being detected through tools like the Lua language server without additional configuration. This has been replaced with a Lua module `mason-test`. `async_test` has also been removed in favour of explicitly making use of the `mason-core.async` API. These changes stands for a significant portion of the diff.
Diffstat (limited to 'tests/mason-core/fetch_spec.lua')
-rw-r--r--tests/mason-core/fetch_spec.lua207
1 files changed, 102 insertions, 105 deletions
diff --git a/tests/mason-core/fetch_spec.lua b/tests/mason-core/fetch_spec.lua
index 107b6417..5a890318 100644
--- a/tests/mason-core/fetch_spec.lua
+++ b/tests/mason-core/fetch_spec.lua
@@ -6,118 +6,115 @@ local stub = require "luassert.stub"
local version = require "mason.version"
describe("fetch", function()
- it(
- "should exhaust all candidates",
- async_test(function()
- stub(spawn, "wget")
- stub(spawn, "curl")
- spawn.wget.returns(Result.failure "wget failure")
- spawn.curl.returns(Result.failure "curl failure")
+ local snapshot
- local result = fetch("https://api.github.com", {
- headers = { ["X-Custom-Header"] = "here" },
- })
- assert.is_true(result:is_failure())
- assert.spy(spawn.wget).was_called(1)
- assert.spy(spawn.curl).was_called(1)
- assert.spy(spawn.wget).was_called_with {
- {
- ("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
- version.VERSION
- ),
- "--header=X-Custom-Header: here",
- },
- "-nv",
- "-o",
- "/dev/null",
- "-O",
- "-",
- "--timeout=30",
- "--method=GET",
- vim.NIL, -- body-data
- "https://api.github.com",
- }
+ before_each(function()
+ snapshot = assert.snapshot()
+ end)
- assert.spy(spawn.curl).was_called_with(match.tbl_containing {
- match.same {
- {
- "-H",
- ("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
- version.VERSION
- ),
- },
- {
- "-H",
- "X-Custom-Header: here",
- },
- },
- "-fsSL",
- match.same { "-X", "GET" },
- vim.NIL, -- data
- vim.NIL, -- out file
- match.same { "--connect-timeout", 30 },
- "https://api.github.com",
- on_spawn = match.is_function(),
- })
- end)
- )
+ after_each(function()
+ snapshot:revert()
+ end)
- it(
- "should return stdout",
- async_test(function()
- stub(spawn, "wget")
- spawn.wget.returns(Result.success {
- stdout = [[{"data": "here"}]],
- })
- local result = fetch "https://api.github.com/data"
- assert.is_true(result:is_success())
- assert.equals([[{"data": "here"}]], result:get_or_throw())
- end)
- )
+ it("should exhaust all candidates", function()
+ stub(spawn, "wget")
+ stub(spawn, "curl")
+ spawn.wget.returns(Result.failure "wget failure")
+ spawn.curl.returns(Result.failure "curl failure")
- it(
- "should respect out_file opt",
- async_test(function()
- stub(spawn, "wget")
- stub(spawn, "curl")
- spawn.wget.returns(Result.failure "wget failure")
- spawn.curl.returns(Result.failure "curl failure")
- fetch("https://api.github.com/data", { out_file = "/test.json" })
+ local result = fetch("https://api.github.com", {
+ headers = { ["X-Custom-Header"] = "here" },
+ })
+ assert.is_true(result:is_failure())
+ assert.spy(spawn.wget).was_called(1)
+ assert.spy(spawn.curl).was_called(1)
+ assert.spy(spawn.wget).was_called_with {
+ {
+ ("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
+ version.VERSION
+ ),
+ "--header=X-Custom-Header: here",
+ },
+ "-nv",
+ "-o",
+ "/dev/null",
+ "-O",
+ "-",
+ "--timeout=30",
+ "--method=GET",
+ vim.NIL, -- body-data
+ "https://api.github.com",
+ }
- assert.spy(spawn.wget).was_called_with {
+ assert.spy(spawn.curl).was_called_with(match.tbl_containing {
+ match.same {
+ {
+ "-H",
+ ("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(version.VERSION),
+ },
{
- ("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
- version.VERSION
- ),
+ "-H",
+ "X-Custom-Header: here",
},
- "-nv",
- "-o",
- "/dev/null",
- "-O",
- "/test.json",
- "--timeout=30",
- "--method=GET",
- vim.NIL, -- body-data
- "https://api.github.com/data",
- }
+ },
+ "-fsSL",
+ match.same { "-X", "GET" },
+ vim.NIL, -- data
+ vim.NIL, -- out file
+ match.same { "--connect-timeout", 30 },
+ "https://api.github.com",
+ on_spawn = match.is_function(),
+ })
+ end)
- assert.spy(spawn.curl).was_called_with(match.tbl_containing {
- match.same {
- {
- "-H",
- ("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
- version.VERSION
- ),
- },
+ it("should return stdout", function()
+ stub(spawn, "curl")
+ spawn.curl.returns(Result.success {
+ stdout = [[{"data": "here"}]],
+ })
+ local result = fetch "https://api.github.com/data"
+ assert.is_true(result:is_success())
+ assert.equals([[{"data": "here"}]], result:get_or_throw())
+ end)
+
+ it("should respect out_file opt", function()
+ stub(spawn, "wget")
+ stub(spawn, "curl")
+ spawn.wget.returns(Result.failure "wget failure")
+ spawn.curl.returns(Result.failure "curl failure")
+ fetch("https://api.github.com/data", { out_file = "/test.json" })
+
+ assert.spy(spawn.wget).was_called_with {
+ {
+ ("--header=User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(
+ version.VERSION
+ ),
+ },
+ "-nv",
+ "-o",
+ "/dev/null",
+ "-O",
+ "/test.json",
+ "--timeout=30",
+ "--method=GET",
+ vim.NIL, -- body-data
+ "https://api.github.com/data",
+ }
+
+ assert.spy(spawn.curl).was_called_with(match.tbl_containing {
+ match.same {
+ {
+ "-H",
+ ("User-Agent: mason.nvim %s (+https://github.com/williamboman/mason.nvim)"):format(version.VERSION),
},
- "-fsSL",
- match.same { "-X", "GET" },
- vim.NIL, -- data
- match.same { "-o", "/test.json" },
- match.same { "--connect-timeout", 30 },
- "https://api.github.com/data",
- on_spawn = match.is_function(),
- })
- end)
- )
+ },
+ "-fsSL",
+ match.same { "-X", "GET" },
+ vim.NIL, -- data
+ match.same { "-o", "/test.json" },
+ match.same { "--connect-timeout", 30 },
+ "https://api.github.com/data",
+ on_spawn = match.is_function(),
+ })
+ end)
end)