-
Notifications
You must be signed in to change notification settings - Fork 25
enh(ci): add installation/uninstallation test for stream-connectors-lib #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sdepassio
merged 5 commits into
develop
from
CTOR-575-add-github-action-to-install-a-stream-connector
Jun 23, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff11186
enh(ci): add installation/uninstallation test for stream-connectors-l…
sdepassio c47fcf2
skip tests with if: false instead of comments
sdepassio c741a82
update for lsqlite3 after rebase
sdepassio baa2b04
updates after reviews
sdepassio 7f6f524
fix
sdepassio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
107 changes: 107 additions & 0 deletions
107
tests/packaging/library/centreon-stream-connectors-lib.lua
This file contains hidden or 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,107 @@ | ||
| #!/usr/bin/env lua | ||
|
|
||
| dofile("tests/packaging/mocks.lua") | ||
|
|
||
| local ok = true | ||
| local function assert_eq(label, expected, result) | ||
| if expected == result then | ||
| print("✓ " .. label) | ||
| else | ||
| print("✗ " .. label .. " (expected=" .. tostring(expected) .. " got=" .. tostring(result) .. ")") | ||
| ok = false | ||
| end | ||
| end | ||
|
|
||
| local function find_lib_path() | ||
| for _, version in ipairs({"5.3", "5.4"}) do | ||
| local path = "/usr/share/lua/" .. version | ||
| local f = io.open(path .. "/centreon-stream-connectors-lib/sc_common.lua", "r") | ||
| if f then | ||
| f:close() | ||
| return path | ||
| end | ||
| end | ||
| end | ||
|
|
||
| local lib_path = find_lib_path() | ||
| if not lib_path then | ||
| print("ERROR: centreon-stream-connectors-lib not found in /usr/share/lua/5.3 or /usr/share/lua/5.4") | ||
| os.exit(1) | ||
| end | ||
| print("Library found at: " .. lib_path) | ||
|
|
||
| -- sc_logger | ||
| local sc_logger = require("centreon-stream-connectors-lib.sc_logger") | ||
| local logger = sc_logger.new("/tmp/test-packaging.log", 3) | ||
| print("✓ sc_logger: loaded and instantiated") | ||
|
|
||
| -- sc_common | ||
| local sc_common = require("centreon-stream-connectors-lib.sc_common") | ||
| local common = sc_common.new(logger) | ||
| print("✓ sc_common: loaded and instantiated") | ||
| assert_eq("sc_common:ifnil_or_empty(nil) → alt", "alt", common:ifnil_or_empty(nil, "alt")) | ||
| assert_eq("sc_common:ifnil_or_empty(\"\") → alt", "alt", common:ifnil_or_empty("", "alt")) | ||
| assert_eq("sc_common:ifnil_or_empty(value) → value", "kept", common:ifnil_or_empty("kept", "alt")) | ||
| assert_eq("sc_common:if_wrong_type(ok) → value", 42, common:if_wrong_type(42, "number", 0)) | ||
| assert_eq("sc_common:if_wrong_type(bad) → default", 0, common:if_wrong_type("str", "number", 0)) | ||
| assert_eq("sc_common:boolean_to_number(true) → 1", 1, common:boolean_to_number(true)) | ||
| assert_eq("sc_common:boolean_to_number(false) → 0", 0, common:boolean_to_number(false)) | ||
| assert_eq("sc_common:split result[1]", "a", common:split("a,b,c", ",")[1]) | ||
| assert_eq("sc_common:split result[3]", "c", common:split("a,b,c", ",")[3]) | ||
| assert_eq("sc_common:compare_numbers(<)", true, common:compare_numbers(1, 2, "<")) | ||
| assert_eq("sc_common:compare_numbers(>)", false, common:compare_numbers(1, 2, ">")) | ||
|
|
||
| -- sc_broker | ||
| local sc_broker = require("centreon-stream-connectors-lib.sc_broker") | ||
| local broker_obj = sc_broker.new(logger) | ||
| print("✓ sc_broker: loaded and instantiated") | ||
| assert_eq("sc_broker:get_host_all_infos(nil) → false", false, broker_obj:get_host_all_infos(nil)) | ||
|
|
||
| -- sc_params | ||
| local sc_params = require("centreon-stream-connectors-lib.sc_params") | ||
| local params = sc_params.new(common, logger) | ||
| print("✓ sc_params: loaded and instantiated") | ||
| assert_eq("sc_params:is_mandatory_config_set(set) → true", true, params:is_mandatory_config_set({"key"}, {key = "value"})) | ||
| assert_eq("sc_params:is_mandatory_config_set(unset) → false", false, params:is_mandatory_config_set({"key"}, {})) | ||
| params:build_accepted_elements_info() | ||
|
|
||
| -- sc_macros | ||
| local sc_macros = require("centreon-stream-connectors-lib.sc_macros") | ||
| local macros = sc_macros.new(params.params, logger, common) | ||
| print("✓ sc_macros: loaded and instantiated") | ||
| assert_eq("sc_macros:transform_short(multiline) → first line", "line1", macros:transform_short("line1\nline2")) | ||
| assert_eq("sc_macros:transform_type(0) → SOFT", "SOFT", macros:transform_type(0)) | ||
| assert_eq("sc_macros:transform_type(1) → HARD", "HARD", macros:transform_type(1)) | ||
| assert_eq("sc_macros:transform_number(\"42\") → 42", 42, macros:transform_number("42")) | ||
| assert_eq("sc_macros:transform_string(3.14) → \"3.14\"", "3.14", macros:transform_string(3.14)) | ||
|
|
||
| -- sc_flush | ||
| local sc_flush = require("centreon-stream-connectors-lib.sc_flush") | ||
| local flush = sc_flush.new(params.params, logger) | ||
| print("✓ sc_flush: loaded and instantiated") | ||
| assert_eq("sc_flush:get_queues_size() → 0", 0, flush:get_queues_size()) | ||
|
|
||
| -- sc_storage | ||
| local sc_storage = require("centreon-stream-connectors-lib.sc_storage") | ||
| local storage = sc_storage.new(common, logger, params.params) | ||
| print("✓ sc_storage: loaded and instantiated") | ||
| assert_eq("sc_storage:is_valid_storage_object(host_1) → true", true, storage:is_valid_storage_object("host_1")) | ||
| assert_eq("sc_storage:is_valid_storage_object(invalid) → false", false, storage:is_valid_storage_object("invalid")) | ||
|
|
||
| -- sc_event | ||
| local sc_event = require("centreon-stream-connectors-lib.sc_event") | ||
| local event = sc_event.new({}, params.params, common, logger, broker_obj, storage) | ||
| print("✓ sc_event: loaded and instantiated") | ||
| assert_eq("sc_event:find_in_mapping(match) → true", true, event:find_in_mapping({neb = 1}, "neb", 1)) | ||
| assert_eq("sc_event:find_in_mapping(no match) → false", false, event:find_in_mapping({neb = 1}, "storage", 1)) | ||
|
|
||
| -- sc_test | ||
| local sc_test = require("centreon-stream-connectors-lib.sc_test") | ||
| print("✓ sc_test: loaded") | ||
| assert_eq("sc_test:compare_result(match) contains OK", true, string.find(sc_test.compare_result("x", "x"), "OK") ~= nil) | ||
| assert_eq("sc_test:compare_result(no match) contains NOK", true, string.find(sc_test.compare_result("x", "y"), "NOK") ~= nil) | ||
|
|
||
| if not ok then | ||
| os.exit(1) | ||
| end | ||
| print("\nAll tests passed!") |
This file contains hidden or 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,14 @@ | ||
| -- Mock the broker globals injected at runtime by Centreon Broker | ||
| broker_log = { | ||
| set_parameters = function() end, | ||
| error = function() end, | ||
| warning = function() end, | ||
| info = function() end, | ||
| } | ||
| broker = { | ||
| bbdo_version = function() return "3.0.0" end, | ||
| json_encode = function() return "{}" end, | ||
| json_decode = function() return {} end, | ||
| } | ||
| -- flexible mock: any method call returns nil without crashing | ||
| broker_cache = setmetatable({}, {__index = function() return function() return nil end end}) |
49 changes: 49 additions & 0 deletions
49
tests/packaging/stream-connectors/test_stream_connector.lua
This file contains hidden or 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,49 @@ | ||
| dofile("tests/packaging/mocks.lua") | ||
|
|
||
| local install_dir = "/usr/share/centreon-broker/lua" | ||
| local ok = true | ||
|
|
||
| local handle = io.popen("find " .. install_dir .. " -maxdepth 1 -name '*.lua' -type f 2>/dev/null") | ||
| if not handle then | ||
| print("Cannot list files in " .. install_dir) | ||
| os.exit(1) | ||
| end | ||
|
|
||
| local files = {} | ||
| for filepath in handle:lines() do | ||
| files[#files + 1] = filepath | ||
| end | ||
| handle:close() | ||
|
|
||
| if #files == 0 then | ||
| print("No Lua files found in " .. install_dir) | ||
| os.exit(1) | ||
| end | ||
|
|
||
| for _, filepath in ipairs(files) do | ||
| local script = filepath:match("([^/]+)$") | ||
| local loaded, load_err = pcall(dofile, filepath) | ||
| if not loaded then | ||
| print("✗ " .. script .. ": load error: " .. tostring(load_err)) | ||
| ok = false | ||
| else | ||
| local inited, init_err = pcall(init, {logfile = "/tmp/test-packaging.log"}) | ||
| if not inited then | ||
| print("✗ " .. script .. ": init() error: " .. tostring(init_err)) | ||
| ok = false | ||
| else | ||
| local wrote, write_err = pcall(write, {}) | ||
| if not wrote then | ||
| print("✗ " .. script .. ": write() error: " .. tostring(write_err)) | ||
| ok = false | ||
| else | ||
| print("✓ " .. script) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| if not ok then | ||
| os.exit(1) | ||
| end | ||
| print("\nAll tests passed!") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.