Skip to content

Commit

Permalink
one assert per testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
PoleTransformer committed Feb 19, 2025
1 parent 725892c commit 492d9f5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 17 deletions.
5 changes: 2 additions & 3 deletions server/monitor-types/websocket-upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ class WebSocketMonitorType extends MonitorType {
async check(monitor, heartbeat, _server) {
const [ message, code ] = await this.attemptUpgrade(monitor);
heartbeat.status = code === 1000 ? UP : DOWN;
//heartbeat.msg = message;
heartbeat.msg = code; //unit testing
console.log(message); //temporary test to pass eslint check
heartbeat.msg = message;
console.log(code, message); //temp unit testing
}

/**
Expand Down
45 changes: 31 additions & 14 deletions test/backend-test/test-websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ describe("Websocket Test", {
status: PENDING,
};

const expected = {
msg: "Unexpected server response: 200",
status: DOWN,
};

await websocketMonitor.check(monitor, heartbeat, {});
assert.strictEqual(heartbeat.status, DOWN);
assert.strictEqual(heartbeat.msg, undefined);
assert.deepStrictEqual(heartbeat, expected);
});

test("Secure Websocket", async () => {
Expand All @@ -36,14 +40,16 @@ describe("Websocket Test", {
status: PENDING,
};

const expected = {
msg: "101 - OK",
status: UP,
};

await websocketMonitor.check(monitor, heartbeat, {});
assert.strictEqual(heartbeat.status, UP);
assert.strictEqual(heartbeat.msg, 1000);
assert.deepStrictEqual(heartbeat, expected);
});

test("Insecure Websocket", {
skip: !!process.env.CI,
}, async () => {
test("Insecure Websocket", async () => {
const websocketMonitor = new WebSocketMonitorType();

const monitor = {
Expand All @@ -56,10 +62,13 @@ describe("Websocket Test", {
status: PENDING,
};

const expected = {
msg: "101 - OK",
status: UP,
};

await websocketMonitor.check(monitor, heartbeat, {});
console.log("Insecure WS Test:", heartbeat.msg, heartbeat.status);
assert.strictEqual(heartbeat.status, UP);
assert.strictEqual(heartbeat.msg, 1000);
assert.deepStrictEqual(heartbeat, expected);
});

test("Test a non compliant WS server without ignore", async () => {
Expand All @@ -75,9 +84,13 @@ describe("Websocket Test", {
status: PENDING,
};

const expected = {
msg: "Invalid Sec-WebSocket-Accept header",
status: DOWN,
};

await websocketMonitor.check(monitor, heartbeat, {});
assert.strictEqual(heartbeat.status, DOWN);
assert.strictEqual(heartbeat.msg, undefined);
assert.deepStrictEqual(heartbeat, expected);
});

test("Test a non compliant WS server with ignore", async () => {
Expand All @@ -93,8 +106,12 @@ describe("Websocket Test", {
status: PENDING,
};

const expected = {
msg: "101 - OK",
status: UP,
};

await websocketMonitor.check(monitor, heartbeat, {});
assert.strictEqual(heartbeat.status, UP);
assert.strictEqual(heartbeat.msg, 1000);
assert.deepStrictEqual(heartbeat, expected);
});
});

0 comments on commit 492d9f5

Please sign in to comment.