42 lines
1.6 KiB
JavaScript
42 lines
1.6 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { createCloudApiServer } from "./server.mjs";
|
|
|
|
test("cloud api exposes /health, /health/live, and /live probes", async () => {
|
|
const server = createCloudApiServer();
|
|
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
|
|
try {
|
|
const { port } = server.address();
|
|
|
|
const health = await fetch(`http://127.0.0.1:${port}/health`);
|
|
assert.equal(health.status, 200);
|
|
const healthPayload = await health.json();
|
|
assert.equal(healthPayload.serviceId, "hwlab-cloud-api");
|
|
assert.equal(healthPayload.environment, "dev");
|
|
assert.equal(healthPayload.commit.id.length > 0, true);
|
|
assert.equal(healthPayload.image.reference.length > 0, true);
|
|
assert.equal(healthPayload.service.id, "hwlab-cloud-api");
|
|
|
|
const healthLive = await fetch(`http://127.0.0.1:${port}/health/live`);
|
|
assert.equal(healthLive.status, 200);
|
|
const healthLivePayload = await healthLive.json();
|
|
assert.equal(healthLivePayload.serviceId, "hwlab-cloud-api");
|
|
assert.equal(healthLivePayload.status, "ok");
|
|
assert.equal(healthLivePayload.commit.id.length > 0, true);
|
|
|
|
const readiness = await fetch(`http://127.0.0.1:${port}/health/live`);
|
|
assert.equal(readiness.status, 200);
|
|
assert.equal((await readiness.json()).status, "ok");
|
|
|
|
const live = await fetch(`http://127.0.0.1:${port}/live`);
|
|
assert.equal(live.status, 200);
|
|
assert.equal((await live.json()).status, "live");
|
|
} finally {
|
|
await new Promise((resolve, reject) => {
|
|
server.close((error) => (error ? reject(error) : resolve()));
|
|
});
|
|
}
|
|
});
|