aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/installer/compiler/compilers/openvsx_spec.lua
blob: d3868a694927528a2e5452aa631999fed097d698 (plain) (blame)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
local Purl = require "mason-core.purl"
local Result = require "mason-core.result"
local common = require "mason-core.installer.managers.common"
local match = require "luassert.match"
local openvsx = require "mason-core.installer.compiler.compilers.openvsx"
local stub = require "luassert.stub"
local test_helpers = require "mason-test.helpers"

---@param overrides Purl
local function purl(overrides)
    local purl = Purl.parse("pkg:openvsx/namespace/name@1.10.1"):get_or_throw()
    if not overrides then
        return purl
    end
    return vim.tbl_deep_extend("force", purl, overrides)
end

describe("openvsx provider :: download :: parsing", function()
    it("should parse download source", function()
        assert.same(
            Result.success {
                download = {
                    file = "file-1.10.1.jar",
                },
                downloads = {
                    {
                        out_file = "file-1.10.1.jar",
                        download_url = "https://open-vsx.org/api/namespace/name/1.10.1/file/file-1.10.1.jar",
                    },
                },
            },
            openvsx.parse({
                download = {
                    file = "file-{{version}}.jar",
                },
            }, purl())
        )
    end)

    it("should parse download source with multiple targets", function()
        assert.same(
            Result.success {
                download = {
                    target = "linux_x64",
                    file = "file-linux-amd64-1.0.0.vsix",
                },
                downloads = {
                    {
                        out_file = "file-linux-amd64-1.0.0.vsix",
                        download_url = "https://open-vsx.org/api/namespace/name/1.0.0/file/file-linux-amd64-1.0.0.vsix",
                    },
                },
            },
            openvsx.parse({
                download = {
                    {
                        target = "win_arm",
                        file = "file-win-arm-{{version}}.vsix",
                    },
                    {
                        target = "linux_x64",
                        file = "file-linux-amd64-{{version}}.vsix",
                    },
                },
            }, purl { version = "1.0.0" }, { target = "linux_x64" })
        )
    end)

    it("should parse download source with output to different directory", function()
        assert.same(
            Result.success {
                download = {
                    file = "out-dir/file-linux-amd64-1.10.1.vsix",
                },
                downloads = {
                    {
                        out_file = "out-dir/file-linux-amd64-1.10.1.vsix",
                        download_url = "https://open-vsx.org/api/namespace/name/1.10.1/file/file-linux-amd64-1.10.1.vsix",
                    },
                },
            },
            openvsx.parse({
                download = {
                    file = "file-linux-amd64-{{version}}.vsix:out-dir/",
                },
            }, purl(), { target = "linux_x64" })
        )
    end)

    it("should recognize target_platform when available", function()
        assert.same(
            Result.success {
                download = {
                    file = "file-linux-1.10.1@win32-arm64.vsix",
                    target = "win_arm64",
                    target_platform = "win32-arm64",
                },
                downloads = {
                    {
                        out_file = "file-linux-1.10.1@win32-arm64.vsix",
                        download_url = "https://open-vsx.org/api/namespace/name/win32-arm64/1.10.1/file/file-linux-1.10.1@win32-arm64.vsix",
                    },
                },
            },
            openvsx.parse({
                download = {
                    {
                        target = "win_arm64",
                        file = "file-linux-{{version}}@win32-arm64.vsix",
                        target_platform = "win32-arm64",
                    },
                },
            }, purl(), { target = "win_arm64" })
        )
    end)
end)

describe("openvsx provider :: download :: installing", function()
    it("should install openvsx assets", function()
        local ctx = test_helpers.create_context()
        stub(common, "download_files", mockx.returns(Result.success()))

        local result = ctx:execute(function()
            return openvsx.install(ctx, {
                download = {
                    file = "file-1.10.1.jar",
                },
                downloads = {
                    {
                        out_file = "file-1.10.1.jar",
                        download_url = "https://open-vsx.org/api/namespace/name/1.10.1/file/file-1.10.1.jar",
                    },
                },
            })
        end)

        assert.is_true(result:is_success())
        assert.spy(common.download_files).was_called(1)
        assert.spy(common.download_files).was_called_with(match.is_ref(ctx), {
            {
                out_file = "file-1.10.1.jar",
                download_url = "https://open-vsx.org/api/namespace/name/1.10.1/file/file-1.10.1.jar",
            },
        })
    end)
end)