-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since the `httpd` role was released this role has been needed support for this feature. After the patch metrics-export-role supports an `httpd` role. It is possible to determine a list of servers that role will reuse in the following configuration. Closes #15
- Loading branch information
1 parent
4c7758c
commit dbde604
Showing
10 changed files
with
1,263 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
local M = {} | ||
|
||
local validate = function (mocks) | ||
if type(mocks) ~= "table" then | ||
error("mocks should have a table type, got " .. type(mocks)) | ||
end | ||
|
||
for _, mock in ipairs(mocks) do | ||
if type(mock.module) ~= "string" then | ||
error("module name should have a string type, got " .. type(mock.module)) | ||
end | ||
local ok, _ = pcall(require, mock.module) | ||
if not ok then | ||
error("cannot require module " .. mock.module) | ||
end | ||
|
||
if type(mock.method) ~= "string" then | ||
error("method name should have a string type, got " .. type(mock.method)) | ||
end | ||
if require(mock.module)[mock.method] == nil then | ||
error("there is no method called " .. mock.method .. " in " .. mock.module) | ||
end | ||
|
||
if type(mock.implementation) ~= "function" then | ||
error("implementation type should be a function, got " .. mock.implementation) | ||
end | ||
end | ||
end | ||
|
||
-- M.init validates mocks and initializes it. | ||
M.init = function (mocks) | ||
validate(mocks) | ||
|
||
M.mocks = {} | ||
for _, mock in ipairs(mocks) do | ||
table.insert(M.mocks, mock) | ||
end | ||
end | ||
|
||
-- M.apply replaces methods from initialized list. | ||
M.apply = function () | ||
for _, mock in ipairs(M.mocks) do | ||
mock.original_implementation = require(mock.module)[mock.method] | ||
require(mock.module)[mock.method] = mock.implementation | ||
end | ||
end | ||
|
||
-- M.delete returns original implementation from mocked method. | ||
M.delete = function () | ||
for _, mock in ipairs(M.mocks) do | ||
require(mock.module)[mock.method] = mock.original_implementation | ||
end | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.