aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/installer
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2026-05-22 20:14:45 +0200
committerGitHub <noreply@github.com>2026-05-22 20:14:45 +0200
commit24e77d5289db0f7b6f4b405683047315b66dc75b (patch)
tree1d40c97d129c8d621d9c9d0645c7c268b49505b2 /tests/mason-core/installer
parentfeat(registry): add registry_cache setting for controlling cache behaviour (#... (diff)
downloadmason-24e77d5289db0f7b6f4b405683047315b66dc75b.tar
mason-24e77d5289db0f7b6f4b405683047315b66dc75b.tar.gz
mason-24e77d5289db0f7b6f4b405683047315b66dc75b.tar.bz2
mason-24e77d5289db0f7b6f4b405683047315b66dc75b.tar.lz
mason-24e77d5289db0f7b6f4b405683047315b66dc75b.tar.xz
mason-24e77d5289db0f7b6f4b405683047315b66dc75b.tar.zst
mason-24e77d5289db0f7b6f4b405683047315b66dc75b.zip
feat: add support for socket.dev firewall client (#2088)
Diffstat (limited to 'tests/mason-core/installer')
-rw-r--r--tests/mason-core/installer/context_spec.lua88
-rw-r--r--tests/mason-core/installer/managers/cargo_spec.lua5
-rw-r--r--tests/mason-core/installer/managers/npm_spec.lua3
-rw-r--r--tests/mason-core/installer/managers/pypi_spec.lua4
4 files changed, 99 insertions, 1 deletions
diff --git a/tests/mason-core/installer/context_spec.lua b/tests/mason-core/installer/context_spec.lua
index 92ef1c49..5b0716c3 100644
--- a/tests/mason-core/installer/context_spec.lua
+++ b/tests/mason-core/installer/context_spec.lua
@@ -2,7 +2,6 @@ local a = require "mason-core.async"
local match = require "luassert.match"
local path = require "mason-core.path"
local pypi = require "mason-core.installer.managers.pypi"
-local registry = require "mason-registry"
local spy = require "luassert.spy"
local stub = require "luassert.stub"
local test_helpers = require "mason-test.helpers"
@@ -279,4 +278,91 @@ cmd.exe /C echo %GREETING% %*]]
assert.equals("Error!", error)
assert.spy(guard).was_called(0)
end)
+
+ describe("system packages", function()
+ local Result = require "mason-core.result"
+ local SystemPackage = require "mason-core.system-package"
+ local _ = require "mason-core.functional"
+
+ local NeedsInstallSystemPackage = SystemPackage:new "needs-install"
+ NeedsInstallSystemPackage.needs_install = _.always(Result.success(true))
+ NeedsInstallSystemPackage.install = _.always(Result.success())
+
+ local InstalledSystemPackage = SystemPackage:new "no-needs-install"
+ InstalledSystemPackage.needs_install = _.always(Result.success(false))
+ InstalledSystemPackage.install = _.always(Result.success())
+
+ local FailingSystemPackage = SystemPackage:new "failing-install"
+ FailingSystemPackage.needs_install = _.always(Result.success(true))
+ FailingSystemPackage.install = _.always(Result.failure "There was an issue.")
+
+ it("should install required system packages", function()
+ local ctx = test_helpers.create_context()
+
+ spy.on(ctx.runner, "suspend")
+ spy.on(ctx.runner, "resume")
+ spy.on(NeedsInstallSystemPackage, "install")
+
+ ctx:execute(function()
+ ctx:require(NeedsInstallSystemPackage)
+ end)
+
+ assert.spy(NeedsInstallSystemPackage.install).was_called(1)
+ assert.spy(ctx.runner.suspend).was_called(1)
+ assert.spy(ctx.runner.resume).was_called(1)
+ end)
+
+ it("should not install required system package if needs_install is false", function()
+ local ctx = test_helpers.create_context()
+
+ spy.on(ctx.runner, "suspend")
+ spy.on(ctx.runner, "resume")
+ spy.on(InstalledSystemPackage, "install")
+
+ ctx:execute(function()
+ ctx:require(InstalledSystemPackage)
+ end)
+
+ assert.spy(InstalledSystemPackage.install).was_called(0)
+ assert.spy(ctx.runner.suspend).was_called(0)
+ assert.spy(ctx.runner.resume).was_called(0)
+ end)
+
+ it("should abort installation if system package installation fails", function()
+ local ctx = test_helpers.create_context()
+ local guard = spy.new()
+
+ spy.on(ctx.runner, "suspend")
+ spy.on(ctx.runner, "resume")
+ spy.on(FailingSystemPackage, "install")
+
+ local result = ctx:execute(function()
+ ctx:require(FailingSystemPackage)
+ guard()
+ end)
+
+ assert.spy(FailingSystemPackage.install).was_called(1)
+ assert.spy(ctx.runner.suspend).was_called(1)
+ assert.spy(ctx.runner.resume).was_called(0)
+ assert.spy(guard).was_called(0)
+ assert.same(result, Result.failure "There was an issue.")
+ end)
+
+ it("should continue installation if system package fails to install but --force is enabled", function()
+ local ctx = test_helpers.create_context { install_opts = { force = true } }
+
+ spy.on(ctx.runner, "suspend")
+ spy.on(ctx.runner, "resume")
+ spy.on(FailingSystemPackage, "install")
+
+ local result = ctx:execute(function()
+ ctx:require(FailingSystemPackage)
+ return Result.success "We forced this."
+ end)
+
+ assert.spy(FailingSystemPackage.install).was_called(1)
+ assert.spy(ctx.runner.suspend).was_called(1)
+ assert.same(result, Result.success "We forced this.")
+ end)
+ end)
end)
diff --git a/tests/mason-core/installer/managers/cargo_spec.lua b/tests/mason-core/installer/managers/cargo_spec.lua
index 66f89ca2..58969855 100644
--- a/tests/mason-core/installer/managers/cargo_spec.lua
+++ b/tests/mason-core/installer/managers/cargo_spec.lua
@@ -20,6 +20,7 @@ describe("cargo manager", function()
vim.NIL, -- features
vim.NIL, -- locked
"my-crate",
+ firewall = true,
}
end)
@@ -53,6 +54,7 @@ describe("cargo manager", function()
vim.NIL, -- features
"--locked", -- locked
"my-crate",
+ firewall = true,
}
end)
@@ -73,6 +75,7 @@ describe("cargo manager", function()
{ "--features", "lsp,cli" }, -- features
vim.NIL, -- locked
"my-crate",
+ firewall = true,
}
end)
@@ -95,6 +98,7 @@ describe("cargo manager", function()
vim.NIL, -- features
vim.NIL, -- locked
"my-crate",
+ firewall = true,
}
end)
@@ -118,6 +122,7 @@ describe("cargo manager", function()
vim.NIL, -- features
vim.NIL, -- locked
"my-crate",
+ firewall = true,
}
end)
end)
diff --git a/tests/mason-core/installer/managers/npm_spec.lua b/tests/mason-core/installer/managers/npm_spec.lua
index 71dca637..e6d5a813 100644
--- a/tests/mason-core/installer/managers/npm_spec.lua
+++ b/tests/mason-core/installer/managers/npm_spec.lua
@@ -72,6 +72,7 @@ describe("npm manager", function()
"my-package@1.0.0",
vim.NIL, -- extra_packages
vim.NIL, -- install_extra_args
+ firewall = true,
}
end)
@@ -89,6 +90,7 @@ describe("npm manager", function()
"my-package@1.0.0",
{ "extra-package" },
vim.NIL, -- install_extra_args
+ firewall = true,
}
end)
@@ -107,6 +109,7 @@ describe("npm manager", function()
"my-package@1.0.0",
vim.NIL, -- extra_packages
{ "--registry", "https://registry.npmjs.org/" }, -- install_extra_args
+ firewall = true,
}
end)
diff --git a/tests/mason-core/installer/managers/pypi_spec.lua b/tests/mason-core/installer/managers/pypi_spec.lua
index 2fdf0002..34a9f8e3 100644
--- a/tests/mason-core/installer/managers/pypi_spec.lua
+++ b/tests/mason-core/installer/managers/pypi_spec.lua
@@ -83,6 +83,7 @@ describe("pypi manager", function()
"--ignore-installed",
{ "--proxy", "http://localhost" },
{ "pip" },
+ firewall = true,
}
end)
@@ -282,6 +283,7 @@ describe("pypi manager", function()
"pypi-package==1.0.0",
vim.NIL, -- extra_packages
},
+ firewall = true,
}
end)
@@ -324,6 +326,7 @@ describe("pypi manager", function()
"pypi-package[lsp]==1.0.0",
vim.NIL, -- extra_packages
},
+ firewall = true,
}
end)
@@ -351,6 +354,7 @@ describe("pypi manager", function()
"pypi-package==1.0.0",
{ "extra-package" },
},
+ firewall = true,
}
end)
end)