Added unit test for unsupported platforms

This commit is contained in:
iotux 2025-12-23 12:46:06 +01:00
parent f5959d2bc5
commit 505b5585e5

View File

@ -15,7 +15,13 @@ describe("SystemServiceMonitorType", () => {
};
});
it("should handle non-existent service gracefully", async () => {
it("should handle non-existent service gracefully", async (t) => {
// Skip this test on macOS/Docker runners where systemctl doesn't exist
if (process.platform !== "linux" && process.platform !== "win32") {
t.skip("Skipping integration test on unsupported platform");
return;
}
const monitor = { system_service_name: "non-existent-service-12345" };
try {
@ -30,6 +36,11 @@ describe("SystemServiceMonitorType", () => {
});
it("should fail gracefully with invalid characters", async () => {
Object.defineProperty(process, "platform", {
value: "linux",
configurable: true
});
const monitor = { system_service_name: "invalid&service;name" };
try {
@ -40,4 +51,22 @@ describe("SystemServiceMonitorType", () => {
assert.strictEqual(heartbeat.status, DOWN);
});
it("should throw error on unsupported platforms", async () => {
// Mock the platform to be 'darwin' (macOS)
Object.defineProperty(process, "platform", {
value: "darwin",
configurable: true
});
const monitor = { system_service_name: "test-service" };
await assert.rejects(
async () => await monitorType.check(monitor, heartbeat),
(err) => {
assert.match(err.message, /not supported on/);
return true;
}
);
});
});