add provider module (#12641)

* implements a Provider singleton, to be used by thirdparty plugins
* exporter: support for thirdparty providers
* splits plugin loading into two steps: discovery and load
  1. get a list of all candidate plugins to load for the different paths
  2. sort providers before on the rest of them and try to load them
This commit is contained in:
Martín Fernández
2024-12-18 19:40:22 +01:00
committed by GitHub
parent 9df814593d
commit e503cc4b9c
5 changed files with 256 additions and 57 deletions

View File

@@ -0,0 +1,41 @@
describe("Provider module", function()
local Provider
local t
setup(function()
require("commonrequire")
Provider = require("provider")
end)
it("should fail to register an improper provider", function()
assert.is_false(Provider:register())
end)
it("should fail to unregister an improper provider", function()
assert.is_false(Provider:unregister())
end)
it("should register a proper provider with empty implementation", function()
assert.is_true(Provider:register("exporter", "test", {}))
end)
it("should override an implementation for the same name of the same kind", function()
assert.is_true(Provider:register("exporter", "test", { test = function() end }))
assert.is_true(type(Provider.features["exporter"]["test"].test) == "function")
end)
it("should unregister a provider", function()
assert.is_true(Provider:unregister("exporter", "test"))
end)
it("should count providers for a specific feature", function()
assert.is_true(Provider:register("exporter", "test1", {}))
assert.is_true(Provider:register("exporter", "test2", {}))
assert.is_true(Provider:register("exporter", "test3", {}))
assert.is_true(Provider:size("exporter") == 3)
end)
it("should dump a table of providers for a specific feature", function()
assert.are.same(Provider.features["exporter"],
Provider:getProvidersTable("exporter"))
end)
it("should dump an empty table for an invalid feature", function()
t = Provider:getProvidersTable("invalid")
assert.is_true(type(t) == "table")
end)
end)