mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-22 19:45:56 +00:00
one assert per testcase
This commit is contained in:
parent
725892c901
commit
492d9f503f
2 changed files with 33 additions and 17 deletions
|
@ -11,9 +11,8 @@ class WebSocketMonitorType extends MonitorType {
|
||||||
async check(monitor, heartbeat, _server) {
|
async check(monitor, heartbeat, _server) {
|
||||||
const [ message, code ] = await this.attemptUpgrade(monitor);
|
const [ message, code ] = await this.attemptUpgrade(monitor);
|
||||||
heartbeat.status = code === 1000 ? UP : DOWN;
|
heartbeat.status = code === 1000 ? UP : DOWN;
|
||||||
//heartbeat.msg = message;
|
heartbeat.msg = message;
|
||||||
heartbeat.msg = code; //unit testing
|
console.log(code, message); //temp unit testing
|
||||||
console.log(message); //temporary test to pass eslint check
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -18,9 +18,13 @@ describe("Websocket Test", {
|
||||||
status: PENDING,
|
status: PENDING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
msg: "Unexpected server response: 200",
|
||||||
|
status: DOWN,
|
||||||
|
};
|
||||||
|
|
||||||
await websocketMonitor.check(monitor, heartbeat, {});
|
await websocketMonitor.check(monitor, heartbeat, {});
|
||||||
assert.strictEqual(heartbeat.status, DOWN);
|
assert.deepStrictEqual(heartbeat, expected);
|
||||||
assert.strictEqual(heartbeat.msg, undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Secure Websocket", async () => {
|
test("Secure Websocket", async () => {
|
||||||
|
@ -36,14 +40,16 @@ describe("Websocket Test", {
|
||||||
status: PENDING,
|
status: PENDING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
msg: "101 - OK",
|
||||||
|
status: UP,
|
||||||
|
};
|
||||||
|
|
||||||
await websocketMonitor.check(monitor, heartbeat, {});
|
await websocketMonitor.check(monitor, heartbeat, {});
|
||||||
assert.strictEqual(heartbeat.status, UP);
|
assert.deepStrictEqual(heartbeat, expected);
|
||||||
assert.strictEqual(heartbeat.msg, 1000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Insecure Websocket", {
|
test("Insecure Websocket", async () => {
|
||||||
skip: !!process.env.CI,
|
|
||||||
}, async () => {
|
|
||||||
const websocketMonitor = new WebSocketMonitorType();
|
const websocketMonitor = new WebSocketMonitorType();
|
||||||
|
|
||||||
const monitor = {
|
const monitor = {
|
||||||
|
@ -56,10 +62,13 @@ describe("Websocket Test", {
|
||||||
status: PENDING,
|
status: PENDING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
msg: "101 - OK",
|
||||||
|
status: UP,
|
||||||
|
};
|
||||||
|
|
||||||
await websocketMonitor.check(monitor, heartbeat, {});
|
await websocketMonitor.check(monitor, heartbeat, {});
|
||||||
console.log("Insecure WS Test:", heartbeat.msg, heartbeat.status);
|
assert.deepStrictEqual(heartbeat, expected);
|
||||||
assert.strictEqual(heartbeat.status, UP);
|
|
||||||
assert.strictEqual(heartbeat.msg, 1000);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Test a non compliant WS server without ignore", async () => {
|
test("Test a non compliant WS server without ignore", async () => {
|
||||||
|
@ -75,9 +84,13 @@ describe("Websocket Test", {
|
||||||
status: PENDING,
|
status: PENDING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
msg: "Invalid Sec-WebSocket-Accept header",
|
||||||
|
status: DOWN,
|
||||||
|
};
|
||||||
|
|
||||||
await websocketMonitor.check(monitor, heartbeat, {});
|
await websocketMonitor.check(monitor, heartbeat, {});
|
||||||
assert.strictEqual(heartbeat.status, DOWN);
|
assert.deepStrictEqual(heartbeat, expected);
|
||||||
assert.strictEqual(heartbeat.msg, undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Test a non compliant WS server with ignore", async () => {
|
test("Test a non compliant WS server with ignore", async () => {
|
||||||
|
@ -93,8 +106,12 @@ describe("Websocket Test", {
|
||||||
status: PENDING,
|
status: PENDING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
msg: "101 - OK",
|
||||||
|
status: UP,
|
||||||
|
};
|
||||||
|
|
||||||
await websocketMonitor.check(monitor, heartbeat, {});
|
await websocketMonitor.check(monitor, heartbeat, {});
|
||||||
assert.strictEqual(heartbeat.status, UP);
|
assert.deepStrictEqual(heartbeat, expected);
|
||||||
assert.strictEqual(heartbeat.msg, 1000);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue