aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-04-18 10:36:25 +0200
committerGitHub <noreply@github.com>2023-04-18 10:36:25 +0200
commit75e64d20c31f8d032916e3990d568a6e38a9d18b (patch)
treee6dbbd462c1b64706dccc38f05a299b8d48c4e56 /tests
parentrefactor(expr): remove redundant core filters and always stringify reduced va... (diff)
downloadmason-75e64d20c31f8d032916e3990d568a6e38a9d18b.tar
mason-75e64d20c31f8d032916e3990d568a6e38a9d18b.tar.gz
mason-75e64d20c31f8d032916e3990d568a6e38a9d18b.tar.bz2
mason-75e64d20c31f8d032916e3990d568a6e38a9d18b.tar.lz
mason-75e64d20c31f8d032916e3990d568a6e38a9d18b.tar.xz
mason-75e64d20c31f8d032916e3990d568a6e38a9d18b.tar.zst
mason-75e64d20c31f8d032916e3990d568a6e38a9d18b.zip
feat(installer): add generic build provider (#1228)
Diffstat (limited to 'tests')
-rw-r--r--tests/mason-core/installer/managers/build_spec.lua70
-rw-r--r--tests/mason-core/installer/registry/expr_spec.lua28
-rw-r--r--tests/mason-core/installer/registry/providers/generic/build_spec.lua143
-rw-r--r--tests/mason-core/installer/registry/providers/generic/download_spec.lua (renamed from tests/mason-core/installer/registry/providers/generic_spec.lua)24
-rw-r--r--tests/mason-core/installer/registry/providers/github/build_spec.lua98
-rw-r--r--tests/mason-core/installer/registry/providers/github/release_spec.lua (renamed from tests/mason-core/installer/registry/providers/github_spec.lua)61
6 files changed, 371 insertions, 53 deletions
diff --git a/tests/mason-core/installer/managers/build_spec.lua b/tests/mason-core/installer/managers/build_spec.lua
new file mode 100644
index 00000000..73dd63c1
--- /dev/null
+++ b/tests/mason-core/installer/managers/build_spec.lua
@@ -0,0 +1,70 @@
+local Result = require "mason-core.result"
+local build = require "mason-core.installer.managers.build"
+local installer = require "mason-core.installer"
+local match = require "luassert.match"
+local mock = require "luassert.mock"
+local spy = require "luassert.spy"
+local stub = require "luassert.stub"
+
+describe("build manager", function()
+ it("should run build instruction", function()
+ local ctx = create_dummy_context()
+ local uv = require "mason-core.async.uv"
+ spy.on(ctx, "promote_cwd")
+ stub(uv, "write")
+ stub(uv, "shutdown")
+ stub(uv, "close")
+ local stdin = mock.new()
+ stub(
+ ctx.spawn,
+ "bash", ---@param args SpawnArgs
+ function(args)
+ args.on_spawn(mock.new(), { stdin })
+ return Result.success()
+ end
+ )
+
+ local result = installer.exec_in_context(ctx, function()
+ return build.run {
+ run = [[npm install && npm run compile]],
+ env = {
+ MASON_VERSION = "2023-03-09",
+ SOME_VALUE = "here",
+ },
+ }
+ end)
+
+ assert.is_true(result:is_success())
+ assert.spy(ctx.promote_cwd).was_called(0)
+ assert.spy(ctx.spawn.bash).was_called(1)
+ assert.spy(ctx.spawn.bash).was_called_with(match.tbl_containing {
+ on_spawn = match.is_function(),
+ env = match.same {
+ MASON_VERSION = "2023-03-09",
+ SOME_VALUE = "here",
+ },
+ })
+ assert.spy(uv.write).was_called(2)
+ assert.spy(uv.write).was_called_with(stdin, "set -euxo pipefail;\n")
+ assert.spy(uv.write).was_called_with(stdin, "npm install && npm run compile")
+ assert.spy(uv.shutdown).was_called_with(stdin)
+ assert.spy(uv.close).was_called_with(stdin)
+ end)
+
+ it("should promote cwd if not staged", function()
+ local ctx = create_dummy_context()
+ stub(ctx, "promote_cwd")
+ stub(ctx.spawn, "bash", mockx.returns(Result.success()))
+
+ local result = installer.exec_in_context(ctx, function()
+ return build.run {
+ run = "make",
+ staged = false,
+ }
+ end)
+
+ assert.is_true(result:is_success())
+ assert.spy(ctx.promote_cwd).was_called(1)
+ assert.spy(ctx.spawn.bash).was_called(1)
+ end)
+end)
diff --git a/tests/mason-core/installer/registry/expr_spec.lua b/tests/mason-core/installer/registry/expr_spec.lua
index f17e49ee..93efa6d4 100644
--- a/tests/mason-core/installer/registry/expr_spec.lua
+++ b/tests/mason-core/installer/registry/expr_spec.lua
@@ -162,6 +162,20 @@ describe("expr filters :: take_if{_not}", function()
greeting = "Hello World!",
})
)
+
+ assert.same(
+ Result.success "",
+ expr.interpolate("{{ take_if(false, greeting) }}", {
+ greeting = "Hello World!",
+ })
+ )
+
+ assert.same(
+ Result.success "Hello World!",
+ expr.interpolate("{{ take_if(true, greeting) }}", {
+ greeting = "Hello World!",
+ })
+ )
end)
it("should not take if value matches", function()
@@ -185,6 +199,20 @@ describe("expr filters :: take_if{_not}", function()
greeting = "Hello World!",
})
)
+
+ assert.same(
+ Result.success "Hello World!",
+ expr.interpolate("{{ take_if_not(false, greeting) }}", {
+ greeting = "Hello World!",
+ })
+ )
+
+ assert.same(
+ Result.success "",
+ expr.interpolate("{{ take_if_not(true, greeting) }}", {
+ greeting = "Hello World!",
+ })
+ )
end)
end)
diff --git a/tests/mason-core/installer/registry/providers/generic/build_spec.lua b/tests/mason-core/installer/registry/providers/generic/build_spec.lua
new file mode 100644
index 00000000..ccc77ac3
--- /dev/null
+++ b/tests/mason-core/installer/registry/providers/generic/build_spec.lua
@@ -0,0 +1,143 @@
+local Purl = require "mason-core.purl"
+local Result = require "mason-core.result"
+local generic = require "mason-core.installer.registry.providers.generic"
+local installer = require "mason-core.installer"
+local stub = require "luassert.stub"
+
+---@param overrides Purl
+local function purl(overrides)
+ local purl = Purl.parse("pkg:generic/namespace/name@v1.2.0"):get_or_throw()
+ if not overrides then
+ return purl
+ end
+ return vim.tbl_deep_extend("force", purl, overrides)
+end
+
+describe("generic provider :: build :: parsing", function()
+ it("should parse single build target", function()
+ assert.same(
+ Result.success {
+ build = {
+ run = "make build",
+ env = {
+ SOME_VALUE = "here",
+ },
+ },
+ },
+ generic.parse({
+ build = {
+ run = "make build",
+ env = {
+ SOME_VALUE = "here",
+ },
+ },
+ }, purl())
+ )
+ end)
+
+ it("should coalesce build target", function()
+ assert.same(
+ Result.success {
+ build = {
+ target = "linux_arm64",
+ run = "make build",
+ env = {
+ LINUX = "yes",
+ },
+ },
+ },
+ generic.parse({
+ build = {
+ {
+ target = "linux_arm64",
+ run = "make build",
+ env = {
+ LINUX = "yes",
+ },
+ },
+ {
+ target = "win_arm64",
+ run = "make build",
+ env = {
+ WINDOWS = "yes",
+ },
+ },
+ },
+ }, purl(), { target = "linux_arm64" })
+ )
+ end)
+
+ it("should interpolate environment", function()
+ assert.same(
+ Result.success {
+ build = {
+ run = "make build",
+ env = {
+ LINUX = "2023-04-18",
+ },
+ },
+ },
+ generic.parse(
+ {
+ build = {
+ run = "make build",
+ env = {
+ LINUX = "{{version}}",
+ },
+ },
+ },
+ purl { version = "2023-04-18" },
+ {
+ target = "linux_arm64",
+ }
+ )
+ )
+ end)
+
+ it("should check supported platforms", function()
+ assert.same(
+ Result.failure "PLATFORM_UNSUPPORTED",
+ generic.parse(
+ {
+ build = {
+ {
+ target = "win_arm64",
+ run = "make build",
+ env = {
+ WINDOWS = "yes",
+ },
+ },
+ },
+ },
+ purl(),
+ {
+ target = "linux_x64",
+ }
+ )
+ )
+ end)
+end)
+
+describe("generic provider :: build :: installing", function()
+ it("should install", function()
+ local ctx = create_dummy_context()
+ local build = require "mason-core.installer.managers.build"
+ stub(build, "run", mockx.returns(Result.success()))
+
+ local result = installer.exec_in_context(ctx, function()
+ return generic.install(ctx, {
+ build = {
+ run = "make",
+ env = { VALUE = "here" },
+ },
+ })
+ end)
+
+ assert.is_true(result:is_success())
+ assert.spy(build.run).was_called(1)
+ assert.spy(build.run).was_called_with {
+ run = "make",
+ env = { VALUE = "here" },
+ }
+ end)
+end)
diff --git a/tests/mason-core/installer/registry/providers/generic_spec.lua b/tests/mason-core/installer/registry/providers/generic/download_spec.lua
index 431703b4..1d3583f9 100644
--- a/tests/mason-core/installer/registry/providers/generic_spec.lua
+++ b/tests/mason-core/installer/registry/providers/generic/download_spec.lua
@@ -13,7 +13,7 @@ local function purl(overrides)
return vim.tbl_deep_extend("force", purl, overrides)
end
-describe("generic provider :: parsing", function()
+describe("generic provider :: download :: parsing", function()
it("should parse single download target", function()
assert.same(
Result.success {
@@ -63,11 +63,29 @@ describe("generic provider :: parsing", function()
end)
it("should check supported platforms", function()
- assert.same(Result.failure "PLATFORM_UNSUPPORTED", generic.parse({ supported_platforms = { "VIC64" } }, purl()))
+ assert.same(
+ Result.failure "PLATFORM_UNSUPPORTED",
+ generic.parse(
+ {
+ download = {
+ {
+ target = "win_arm64",
+ files = {
+ ["name.tar.gz"] = [[https://getpackage.org/downloads/win-aarch64/{{version | strip_prefix "v"}}/name.tar.gz]],
+ },
+ },
+ },
+ },
+ purl(),
+ {
+ target = "linux_arm64",
+ }
+ )
+ )
end)
end)
-describe("generic provider :: installing", function()
+describe("generic provider :: download :: installing", function()
it("should install generic packages", function()
local ctx = create_dummy_context()
local std = require "mason-core.installer.managers.std"
diff --git a/tests/mason-core/installer/registry/providers/github/build_spec.lua b/tests/mason-core/installer/registry/providers/github/build_spec.lua
new file mode 100644
index 00000000..b25c26d8
--- /dev/null
+++ b/tests/mason-core/installer/registry/providers/github/build_spec.lua
@@ -0,0 +1,98 @@
+local Purl = require "mason-core.purl"
+local Result = require "mason-core.result"
+local github = require "mason-core.installer.registry.providers.github"
+local installer = require "mason-core.installer"
+local match = require "luassert.match"
+local mock = require "luassert.mock"
+local stub = require "luassert.stub"
+
+---@param overrides Purl
+local function purl(overrides)
+ local purl = Purl.parse("pkg:github/namespace/name@2023-03-09"):get_or_throw()
+ if not overrides then
+ return purl
+ end
+ return vim.tbl_deep_extend("force", purl, overrides)
+end
+
+describe("github provider :: build :: parsing", function()
+ it("should parse build source", function()
+ assert.same(
+ Result.success {
+ build = {
+ run = [[npm install && npm run compile]],
+ env = { MASON_VERSION = "2023-03-09" },
+ },
+ repo = "https://github.com/namespace/name.git",
+ rev = "2023-03-09",
+ },
+ github.parse({
+ build = {
+ run = [[npm install && npm run compile]],
+ },
+ }, purl())
+ )
+ end)
+
+ it("should parse build source with multiple targets", function()
+ assert.same(
+ Result.success {
+ build = {
+ target = "win_x64",
+ run = [[npm install]],
+ env = { MASON_VERSION = "2023-03-09" },
+ },
+ repo = "https://github.com/namespace/name.git",
+ rev = "2023-03-09",
+ },
+ github.parse({
+ build = {
+ {
+ target = "linux_arm64",
+ run = [[npm install && npm run compile]],
+ },
+ {
+ target = "win_x64",
+ run = [[npm install]],
+ },
+ },
+ }, purl(), { target = "win_x64" })
+ )
+ end)
+end)
+
+describe("github provider :: build :: installing", function()
+ it("should install github build sources", function()
+ local ctx = create_dummy_context()
+ local std = require "mason-core.installer.managers.std"
+ local build = require "mason-core.installer.managers.build"
+ stub(std, "clone", mockx.returns(Result.success()))
+ stub(build, "run", mockx.returns(Result.success()))
+
+ local result = installer.exec_in_context(ctx, function()
+ return github.install(ctx, {
+ repo = "namespace/name",
+ rev = "2023-03-09",
+ build = {
+ run = [[npm install && npm run compile]],
+ env = {
+ MASON_VERSION = "2023-03-09",
+ SOME_VALUE = "here",
+ },
+ },
+ }, purl())
+ end)
+
+ assert.is_true(result:is_success())
+ assert.spy(std.clone).was_called(1)
+ assert.spy(std.clone).was_called_with("namespace/name", { rev = "2023-03-09" })
+ assert.spy(build.run).was_called(1)
+ assert.spy(build.run).was_called_with {
+ run = [[npm install && npm run compile]],
+ env = {
+ MASON_VERSION = "2023-03-09",
+ SOME_VALUE = "here",
+ },
+ }
+ end)
+end)
diff --git a/tests/mason-core/installer/registry/providers/github_spec.lua b/tests/mason-core/installer/registry/providers/github/release_spec.lua
index 58917f4d..6d0ff5df 100644
--- a/tests/mason-core/installer/registry/providers/github_spec.lua
+++ b/tests/mason-core/installer/registry/providers/github/release_spec.lua
@@ -3,7 +3,6 @@ local Result = require "mason-core.result"
local github = require "mason-core.installer.registry.providers.github"
local installer = require "mason-core.installer"
local match = require "luassert.match"
-local mock = require "luassert.mock"
local registry_installer = require "mason-core.installer.registry"
local spy = require "luassert.spy"
local stub = require "luassert.stub"
@@ -17,7 +16,7 @@ local function purl(overrides)
return vim.tbl_deep_extend("force", purl, overrides)
end
-describe("github provider :: parsing", function()
+describe("github provider :: release :: parsing", function()
it("should parse release asset source", function()
assert.same(
Result.success {
@@ -157,7 +156,10 @@ describe("github provider :: parsing", function()
it("should parse build source", function()
assert.same(
Result.success {
- build = { run = [[npm install && npm run compile]] },
+ build = {
+ run = [[npm install && npm run compile]],
+ env = { MASON_VERSION = "2023-03-09" },
+ },
repo = "https://github.com/namespace/name.git",
rev = "2023-03-09",
},
@@ -172,7 +174,11 @@ describe("github provider :: parsing", function()
it("should parse build source with multiple targets", function()
assert.same(
Result.success {
- build = { target = "win_x64", run = [[npm install]] },
+ build = {
+ target = "win_x64",
+ run = [[npm install]],
+ env = { MASON_VERSION = "2023-03-09" },
+ },
repo = "https://github.com/namespace/name.git",
rev = "2023-03-09",
},
@@ -261,7 +267,7 @@ describe("github provider :: parsing", function()
end)
end)
-describe("github provider :: installing", function()
+describe("github provider :: release :: installing", function()
it("should install github release assets", function()
local ctx = create_dummy_context()
local std = require "mason-core.installer.managers.std"
@@ -375,49 +381,4 @@ describe("github provider :: installing", function()
assert.same(Result.failure [[Version "1.42.0" is not available.]], result)
assert.spy(std.download_file).was_called(0)
end)
-
- it("should install github build sources", function()
- local ctx = create_dummy_context()
- local std = require "mason-core.installer.managers.std"
- local uv = require "mason-core.async.uv"
- stub(uv, "write")
- stub(uv, "shutdown")
- stub(uv, "close")
- local stdin = mock.new()
- stub(std, "clone", mockx.returns(Result.success()))
- stub(
- ctx.spawn,
- "bash", ---@param args SpawnArgs
- function(args)
- args.on_spawn(mock.new(), { stdin })
- return Result.success()
- end
- )
-
- local result = installer.exec_in_context(ctx, function()
- return github.install(ctx, {
- repo = "namespace/name",
- rev = "2023-03-09",
- build = {
- run = [[npm install && npm run compile]],
- },
- }, purl { version = "2023-03-09" })
- end)
-
- assert.is_true(result:is_success())
- assert.spy(std.clone).was_called(1)
- assert.spy(std.clone).was_called_with("namespace/name", { rev = "2023-03-09" })
- assert.spy(ctx.spawn.bash).was_called(1)
- assert.spy(ctx.spawn.bash).was_called_with(match.tbl_containing {
- on_spawn = match.is_function(),
- env = match.same {
- MASON_VERSION = "2023-03-09",
- },
- })
- assert.spy(uv.write).was_called(2)
- assert.spy(uv.write).was_called_with(stdin, "set -euxo pipefail;\n")
- assert.spy(uv.write).was_called_with(stdin, "npm install && npm run compile")
- assert.spy(uv.shutdown).was_called_with(stdin)
- assert.spy(uv.close).was_called_with(stdin)
- end)
end)