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
|
local mock = require "luassert.mock"
local stub = require "luassert.stub"
local Optional = require "mason-core.optional"
local Result = require "mason-core.result"
local github = require "mason-core.managers.github"
local installer = require "mason-core.installer"
local providers = require "mason-core.providers"
describe("github release file", function()
it(
"should use provided version",
async_test(function()
stub(providers.github, "get_latest_release")
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
installer.prepare_installer(ctx)
local source = installer.exec_in_context(ctx, function()
return github.release_file {
repo = "williamboman/mason.nvim",
asset_file = "program.exe",
version = Optional.of "13.37",
}
end)
assert.spy(providers.github.get_latest_release).was_not_called()
assert.equals("13.37", source.release)
assert.equals(
"https://github.com/williamboman/mason.nvim/releases/download/13.37/program.exe",
source.download_url
)
end)
)
it(
"should use use dynamic asset_file",
async_test(function()
stub(providers.github, "get_latest_release")
providers.github.get_latest_release.returns(Result.success(mock.new {
tag_name = "im_the_tag",
}))
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
installer.prepare_installer(ctx)
local source = installer.exec_in_context(ctx, function()
return github.release_file {
repo = "williamboman/mason.nvim",
asset_file = function(version)
return version .. "_for_reals"
end,
}
end)
assert.spy(providers.github.get_latest_release).was_called(1)
assert.spy(providers.github.get_latest_release).was_called_with "williamboman/mason.nvim"
assert.equals("im_the_tag", source.release)
assert.equals("im_the_tag_for_reals", source.asset_file)
assert.equals(
"https://github.com/williamboman/mason.nvim/releases/download/im_the_tag/im_the_tag_for_reals",
source.download_url
)
end)
)
end)
describe("github release version", function()
it(
"should use provided version",
async_test(function()
stub(providers.github, "get_latest_release")
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
installer.prepare_installer(ctx)
local source = installer.exec_in_context(ctx, function()
return github.release_version {
repo = "williamboman/mason.nvim",
version = Optional.of "13.37",
}
end)
assert.spy(providers.github.get_latest_release).was_not_called()
assert.equals("13.37", source.release)
end)
)
it(
"should fetch latest release from GitHub API",
async_test(function()
async_test(function()
stub(providers.github, "get_latest_release")
providers.github.get_latest_release.returns(Result.success { tag_name = "v42" })
local handle = InstallHandleGenerator "dummy"
local ctx = InstallContextGenerator(handle)
installer.prepare_installer(ctx)
local source = installer.exec_in_context(ctx, function()
return github.release_version {
repo = "williamboman/mason.nvim",
}
end)
assert.spy(providers.github.get_latest_release).was_called(1)
assert.spy(providers.github.get_latest_release).was_called_with "williamboman/mason.nvim"
assert.equals("v42", source.release)
end)
end)
)
end)
|