• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nightconcept / almandine / 14716629923

28 Apr 2025 07:54PM UTC coverage: 95.996%. First build
14716629923

push

github

web-flow
feat: Initial features (#1)

863 of 899 new or added lines in 16 files covered. (96.0%)

863 of 899 relevant lines covered (96.0%)

1.99 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.46
/src/spec/modules/install_spec.lua
1
--[[
2
  Install Module Specification
3

4
  Busted test suite for install_dependencies in src/modules/install.lua.
5
  - Verifies correct installation of dependencies from manifest.
6
  - Ensures manifest is not modified and only manifest dependencies are installed.
7
]]
8
--
9

10
-- luacheck: globals describe it assert
11

12
--- Install module specification for Busted.
13
-- @module install_spec
14

15
describe("install_module.install_dependencies", function()
2✔
16
  local install_mod = require("modules.install")
1✔
17
  local install_dependencies = install_mod.install_dependencies
1✔
18

19
  local function make_manifest(deps)
20
    local manifest = { dependencies = deps or {} }
2✔
21
    return function()
22
      return manifest, nil
2✔
23
    end
24
  end
25

26
  local function ensure_lib_dir() end
5✔
27

28
  local function make_downloader()
29
    local downloads = {}
4✔
30
    return {
4✔
31
      download = function(url, out_path)
32
        table.insert(downloads, { url = url, out_path = out_path })
5✔
33
        if url and out_path then
5✔
34
          return true
5✔
35
        end
NEW
36
        return false, "invalid args"
×
37
      end,
38
      get_downloads = function()
39
        return downloads
5✔
40
      end,
41
    }
4✔
42
  end
43

44
  it("installs all dependencies from manifest", function()
2✔
45
    local deps = {
1✔
46
      foo = "https://example.com/foo.lua",
1✔
47
      bar = { url = "https://example.com/bar.lua", path = "custom/bar.lua" },
1✔
48
    }
49
    local load = make_manifest(deps)
1✔
50
    local downloader = make_downloader()
1✔
51
    local utils = { downloader = downloader }
1✔
52
    install_dependencies(nil, load, ensure_lib_dir, downloader, utils)
1✔
53
    local downloads = downloader.get_downloads()
1✔
54
    assert.are.equal(#downloads, 2)
1✔
55
    local found_foo, found_bar, found_custom = false, false, false
1✔
56
    for _, d in ipairs(downloads) do
3✔
57
      if d.url == "https://example.com/foo.lua" then
2✔
58
        found_foo = true
1✔
59
      end
60
      if d.url == "https://example.com/bar.lua" then
2✔
61
        found_bar = true
1✔
62
      end
63
      if d.out_path == "custom/bar.lua" then
2✔
64
        found_custom = true
1✔
65
      end
66
    end
67
    assert.is_true(found_foo and found_bar and found_custom)
1✔
68
  end)
69

70
  it("installs only the specified dependency", function()
2✔
71
    local deps = {
1✔
72
      foo = "https://example.com/foo.lua",
1✔
73
      bar = "https://example.com/bar.lua",
1✔
74
    }
75
    local load = make_manifest(deps)
1✔
76
    local downloader = make_downloader()
1✔
77
    local utils = { downloader = downloader }
1✔
78
    install_dependencies("foo", load, ensure_lib_dir, downloader, utils)
1✔
79
    local downloads = downloader.get_downloads()
1✔
80
    assert.are.equal(#downloads, 1)
1✔
81
    assert.are.equal(downloads[1].url, "https://example.com/foo.lua")
1✔
82
  end)
83

84
  it("installs from lockfile_deps table", function()
2✔
85
    local lockfile_deps = {
1✔
86
      foo = "https://example.com/foo.lua",
1✔
87
      bar = { url = "https://example.com/bar.lua", path = "custom/bar.lua" },
1✔
88
    }
89
    local load = function()
NEW
90
      error("should not call load_manifest when lockfile_deps provided")
×
91
    end
92
    local downloader = make_downloader()
1✔
93
    local utils = { downloader = downloader }
1✔
94
    install_dependencies(nil, load, ensure_lib_dir, downloader, utils, lockfile_deps)
1✔
95
    local downloads = downloader.get_downloads()
1✔
96
    assert.are.equal(#downloads, 2)
1✔
97
    local found_foo, found_bar, found_custom = false, false, false
1✔
98
    for _, d in ipairs(downloads) do
3✔
99
      if d.url == "https://example.com/foo.lua" then
2✔
100
        found_foo = true
1✔
101
      end
102
      if d.url == "https://example.com/bar.lua" then
2✔
103
        found_bar = true
1✔
104
      end
105
      if d.out_path == "custom/bar.lua" then
2✔
106
        found_custom = true
1✔
107
      end
108
    end
109
    assert.is_true(found_foo and found_bar and found_custom)
1✔
110
  end)
111

112
  it("prints error and returns if manifest fails to load", function()
2✔
113
    local load = function()
114
      return nil, "load error!"
1✔
115
    end
116
    local downloader = make_downloader()
1✔
117
    local utils = { downloader = downloader }
1✔
118
    local printed = nil
1✔
119
    local print_stub = require("luassert.stub")(_G, "print", function(msg)
2✔
120
      printed = msg
1✔
121
    end)
122
    install_dependencies(nil, load, ensure_lib_dir, downloader, utils)
1✔
123
    print_stub:revert()
1✔
124
    assert.is_truthy(type(printed) == "string" and printed:match("load error!"))
1✔
125
    assert.is_true(type(#downloader.get_downloads()) == "number" and #downloader.get_downloads() == 0)
1✔
126
  end)
127

128
  describe("lockfile submodule", function()
2✔
129
    local lockfile = install_mod.lockfile
1✔
130

131
    it("generates lockfile table with all fields", function()
2✔
132
      local resolved = {
1✔
133
        foo = { hash = "abc", version = "1.0", source = "src" },
1✔
134
        bar = { hash = "def" },
1✔
135
      }
136
      local tbl = lockfile.generate_lockfile_table(resolved)
1✔
137
      assert.are.equal(tbl.api_version, "1")
1✔
138
      assert.is_table(tbl.package)
1✔
139
      assert.are.equal(tbl.package.foo.hash, "abc")
1✔
140
      assert.are.equal(tbl.package.foo.version, "1.0")
1✔
141
      assert.are.equal(tbl.package.foo.source, "src")
1✔
142
      assert.are.equal(tbl.package.bar.hash, "def")
1✔
143
    end)
144

145
    it("errors if resolved_deps is not a table", function()
2✔
146
      assert.has_error(function()
2✔
147
        lockfile.generate_lockfile_table(nil)
1✔
148
      end)
149
    end)
150

151
    it("errors if dependency entry is not a table", function()
2✔
152
      local resolved = { foo = "notatable" }
1✔
153
      assert.has_error(function()
2✔
154
        lockfile.generate_lockfile_table(resolved)
1✔
155
      end)
156
    end)
157

158
    it("errors if dependency entry is missing hash", function()
2✔
159
      local resolved = { foo = {} }
1✔
160
      assert.has_error(function()
2✔
161
        lockfile.generate_lockfile_table(resolved)
1✔
162
      end)
163
    end)
164

165
    it("serializes lockfile table to Lua string", function()
2✔
166
      local tbl = { api_version = "1", package = { foo = { hash = "abc" } } }
1✔
167
      local str = lockfile.serialize_lockfile(tbl)
1✔
168
      assert.is_truthy(type(str) == "string" and str:match("return"))
1✔
169
    end)
170

171
    it("errors if serialize_lockfile arg is not a table", function()
2✔
172
      assert.has_error(function()
2✔
173
        lockfile.serialize_lockfile(nil)
1✔
174
      end)
175
    end)
176

177
    it("writes lockfile to disk and returns true", function()
2✔
178
      local tbl = { api_version = "1", package = { foo = { hash = "abc" } } }
1✔
179
      local io_stub = require("luassert.stub")(io, "open", function(_path, mode)
2✔
180
        assert.are.equal(mode, "w")
1✔
181
        return { write = function() end, close = function() end }, nil
3✔
182
      end)
183
      local ok, path_out = lockfile.write_lockfile(tbl, "test-lock.lua")
1✔
184
      io_stub:revert()
1✔
185
      assert.is_true(ok)
1✔
186
      assert.are.equal(path_out, "test-lock.lua")
1✔
187
    end)
188

189
    it("returns false and error if file cannot be opened", function()
2✔
190
      local tbl = { api_version = "1", package = { foo = { hash = "abc" } } }
1✔
191
      local io_stub = require("luassert.stub")(io, "open", function()
2✔
192
        return nil, "fail open"
1✔
193
      end)
194
      local ok, err = lockfile.write_lockfile(tbl, "bad-path")
1✔
195
      io_stub:revert()
1✔
196
      assert.is_false(ok)
1✔
197
      assert.are.equal(err, "fail open")
1✔
198
    end)
199
  end)
200

201
  it("prints help_info output", function()
2✔
202
    local help = install_mod.help_info
1✔
203
    local printed = {}
1✔
204
    local print_stub = require("luassert.stub")(_G, "print", function(msg)
2✔
205
      table.insert(printed, msg)
1✔
206
    end)
207
    help()
1✔
208
    print_stub:revert()
1✔
209
    assert.is_truthy(#printed > 0 and tostring(printed[1]):match("Usage: almd install"))
1✔
210
  end)
211
end)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc