Skip to content

Commit

Permalink
test: add tests for custom healthcheck endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
gjvis committed Jun 29, 2017
1 parent 7ec2f57 commit 18becc0
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion test/functional/healthcheck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ test('proxy requests originating from behind the broker client', t => {
const clientPort = port();
let client = app.main({ port: clientPort });

t.plan(6);
t.plan(7);

const serverHealth = `http://localhost:${serverPort}/healthcheck`;
const connectionStatus = `http://localhost:${serverPort}/` +
`connection-status/${BROKER_TOKEN}`;
const clientHealth = `http://localhost:${clientPort}/healthcheck`;

// instantiated and connected later
let customHealthClient;

t.test('server healthcheck', t => {
request({url: serverHealth, json: true }, (err, res) => {
if (err) { return t.threw(err); }
Expand Down Expand Up @@ -95,7 +99,33 @@ test('proxy requests originating from behind the broker client', t => {
}, 20);
});

t.test('custom healthcheck endpoint', t => {
// launch second client to test custom client healthcheck
process.env.BROKER_HEALTHCHECK_PATH = '/custom/healthcheck/endpoint';
const customClientPort = port();
const customClientHealth =
`http://localhost:${customClientPort}/custom/healthcheck/endpoint`;

customHealthClient = app.main({ port: customClientPort });

server.io.once('connection', socket => {
socket.once('identify', () => {
t.test('client custom healthcheck', t => {
request({url: customClientHealth, json: true }, (err, res) => {
if (err) { return t.threw(err); }

t.equal(res.statusCode, 200, '200 statusCode');
t.equal(res.body['ok'], true, '{ ok: true } in body');
t.end();
});
});
t.end();
});
});
});

t.test('clean up', t => {
customHealthClient.close();
client.close();
setTimeout(() => {
server.close();
Expand Down

0 comments on commit 18becc0

Please sign in to comment.