Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
263 changes: 238 additions & 25 deletions .github/actions/test-packages/action.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .github/workflows/lua-cffi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ jobs:
package_extension: ${{ matrix.package_extension }}
distrib: ${{ matrix.distrib }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-lua-cffi-${{ matrix.distrib }}
test_type: dependency

- name: Upload error log
if: failure()
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lua-lsqlite3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ jobs:
package_extension: ${{ matrix.package_extension }}
distrib: ${{ matrix.distrib }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-lua-lsqlite3-${{ matrix.distrib }}
test_type: dependency

- name: Upload error log
if: failure()
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lua-sql-mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ jobs:
package_extension: ${{ matrix.package_extension }}
distrib: ${{ matrix.distrib }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-rpm-lua-sql-mysql-${{ matrix.distrib }}
test_type: dependency

- name: Upload error log
if: failure()
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lua-tz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ jobs:
package_extension: ${{ matrix.package_extension }}
distrib: ${{ matrix.distrib }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-lua-tz-${{ matrix.distrib }}
test_type: dependency

- name: Upload error log
if: failure()
Expand Down
60 changes: 56 additions & 4 deletions .github/workflows/stream-connectors-lib.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,65 @@ jobs:
stability: ${{ needs.get-environment.outputs.stability }}
artifact_name: "package-stream-connectors-lib-${{ matrix.distrib }}"

test-packages:
needs: [get-environment, package]
strategy:
fail-fast: false
matrix:
include:
- package_extension: rpm
image: almalinux:8
distrib: el8
- package_extension: rpm
image: almalinux:9
distrib: el9
# - package_extension: rpm
# image: almalinux:10
# distrib: el10
- package_extension: deb
image: debian:bullseye
distrib: bullseye
- package_extension: deb
image: debian:bookworm
distrib: bookworm
# - package_extension: deb
# image: debian:trixie
# distrib: trixie
- package_extension: deb
image: ubuntu:jammy
distrib: jammy
- package_extension: deb
image: ubuntu:noble
distrib: noble
runs-on: ubuntu-24.04
container:
image: ${{ matrix.image }}
name: test packages on ${{ matrix.package_extension }} ${{ matrix.distrib }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Test packaged libs
uses: ./.github/actions/test-packages
with:
package_extension: ${{ matrix.package_extension }}
distrib: ${{ matrix.distrib }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.distrib }}
test_type: library

- name: Upload error log
if: failure()
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: install_error_log_${{ matrix.distrib }}
path: install_error_${{ matrix.distrib }}.log

deliver-rpm:
if: ${{ contains(fromJson('["unstable", "testing", "stable"]'), needs.get-environment.outputs.stability) }}
needs: [get-environment, package]
needs: [get-environment, package, test-packages]
runs-on: ubuntu-24.04
strategy:
matrix:
distrib: [el8, el9, el10]
distrib: [el8, el9] #, el10]
name: deliver ${{ matrix.distrib }}

steps:
Expand All @@ -116,11 +168,11 @@ jobs:

deliver-deb:
if: ${{ contains(fromJson('["unstable", "testing", "stable"]'), needs.get-environment.outputs.stability) }}
needs: [get-environment, package]
needs: [get-environment, package, test-packages]
runs-on: ubuntu-24.04
strategy:
matrix:
distrib: [bullseye, bookworm, trixie, jammy, noble]
distrib: [bullseye, bookworm, jammy, noble] #, trixie, jammy, noble]
name: deliver ${{ matrix.distrib }}

steps:
Expand Down
63 changes: 59 additions & 4 deletions .github/workflows/stream-connectors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,68 @@ jobs:
stability: ${{ needs.get-environment.outputs.stability }}
artifact_name: "package-${{ matrix.connector_path }}-${{ matrix.distrib }}"

test-packages:
if: false
needs: [get-environment, detect-changes, package]
strategy:
fail-fast: false
matrix:
distrib: [el8, el9, el10, bullseye, bookworm, trixie, jammy, noble]
connector_path: ${{ fromJson(needs.detect-changes.outputs.connectors) }}
include:
- distrib: el8
package_extension: rpm
image: almalinux:8
- distrib: el9
package_extension: rpm
image: almalinux:9
# - distrib: el10
# package_extension: rpm
# image: almalinux:10
- distrib: bullseye
package_extension: deb
image: debian:bullseye
- distrib: bookworm
package_extension: deb
image: debian:bookworm
# - distrib: trixie
# package_extension: deb
# image: debian:trixie
- distrib: jammy
package_extension: deb
image: ubuntu:jammy
- distrib: noble
package_extension: deb
image: ubuntu:noble
runs-on: ubuntu-24.04
container:
image: ${{ matrix.image }}
name: Test ${{ matrix.distrib }} ${{ matrix.connector_path }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Test packaged connector
uses: ./.github/actions/test-packages
with:
package_extension: ${{ matrix.package_extension }}
distrib: ${{ matrix.distrib }}
cache_key: ${{ github.sha }}-${{ github.run_id }}-${{ matrix.package_extension }}-${{ matrix.connector_path }}-${{ matrix.distrib }}
test_type: stream-connector

- name: Upload error log
if: failure()
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: install_error_log_${{ matrix.connector_path }}_${{ matrix.distrib }}
path: install_error_${{ matrix.distrib }}.log

deliver-rpm:
if: ${{ contains(fromJson('["unstable", "testing", "stable"]'), needs.get-environment.outputs.stability) }}
needs: [get-environment, detect-changes, package]
needs: [get-environment, detect-changes, package, test-packages]
runs-on: ubuntu-24.04
strategy:
matrix:
distrib: [el8, el9, el10]
distrib: [el8, el9] #, el10]
connector_path: ${{ fromJson(needs.detect-changes.outputs.connectors) }}
name: Deliver ${{ matrix.distrib }} ${{ matrix.connector_path }}

Expand All @@ -193,11 +248,11 @@ jobs:

deliver-deb:
if: ${{ contains(fromJson('["unstable", "testing", "stable"]'), needs.get-environment.outputs.stability) }}
needs: [get-environment, detect-changes, package]
needs: [get-environment, detect-changes, package, test-packages]
runs-on: ubuntu-24.04
strategy:
matrix:
distrib: [bullseye, bookworm, trixie, jammy, noble]
distrib: [bullseye, bookworm, jammy, noble] #, trixie, jammy, noble]
connector_path: ${{ fromJson(needs.detect-changes.outputs.connectors) }}
name: Deliver ${{ matrix.distrib }} ${{ matrix.connector_path }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ overrides:
rpm:
depends:
- lua-socket >= 3.0
- centreon-broker-core >= 24.10.0
- centreon-broker-core >= 24.04.0
- lua-curl >= 0.3.13-10
- lua
deb:
depends:
- "centreon-broker-core (>= 24.10.0)"
Comment thread
sdepassio marked this conversation as resolved.
- "centreon-broker-core (>= 24.04.0)"
- "lua-socket (>= 3.0~)"
- "lua-curl (>= 0.3.13-10)"
- "lua@luaver@"
Expand Down
File renamed without changes.
107 changes: 107 additions & 0 deletions tests/packaging/library/centreon-stream-connectors-lib.lua
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!")
14 changes: 14 additions & 0 deletions tests/packaging/mocks.lua
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 tests/packaging/stream-connectors/test_stream_connector.lua
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!")
Loading