Skip to content

Commit

Permalink
feat: accept HEAD requests (closes #47)
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Oct 18, 2022
1 parent 8fe3ec5 commit 2f85c6c
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions test/lightship/factories/createLightship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
} from '../../../src/types';

type ProbeState = {
readonly message: string,
readonly message?: string,
readonly status: number,
};

Expand All @@ -36,7 +36,7 @@ const getLightshipPort = (lightship: Lightship) => {
return address.port;
};

const getServiceState = async (lightship: Lightship, method: 'GET'): Promise<ServiceState> => {
const getServiceState = async (lightship: Lightship, method: 'GET' | 'HEAD'): Promise<ServiceState> => {
const port = getLightshipPort(lightship);

const health = await axios('http://127.0.0.1:' + port + '/health', {
Expand Down Expand Up @@ -103,6 +103,28 @@ test('server starts in SERVER_IS_NOT_READY state', async (t) => {
t.is(terminate.called, false);
});

test('server starts in SERVER_IS_NOT_READY state (HEAD)', async (t) => {
const terminate = stub();

const lightship = await createLightship({
shutdownDelay: 0,
terminate,
});

t.is(lightship.isServerReady(), false);
t.is(lightship.isServerShuttingDown(), false);

const serviceState = await getServiceState(lightship, 'HEAD');

t.is(serviceState.health.status, 500);
t.is(serviceState.live.status, 200);
t.is(serviceState.ready.status, 500);

await lightship.shutdown();

t.is(terminate.called, false);
});

test('calling `signalReady` changes server state to SERVER_IS_READY', async (t) => {
const terminate = stub();

Expand Down Expand Up @@ -132,6 +154,30 @@ test('calling `signalReady` changes server state to SERVER_IS_READY', async (t)
t.is(terminate.called, false);
});

test('calling `signalReady` changes server state to SERVER_IS_READY (HEAD)', async (t) => {
const terminate = stub();

const lightship = await createLightship({
shutdownDelay: 0,
terminate,
});

lightship.signalReady();

t.is(lightship.isServerReady(), true);
t.is(lightship.isServerShuttingDown(), false);

const serviceState = await getServiceState(lightship, 'GET');

t.is(serviceState.health.status, 200);
t.is(serviceState.live.status, 200);
t.is(serviceState.ready.status, 200);

await lightship.shutdown();

t.is(terminate.called, false);
});

test('returns service state multiple time', async (t) => {
const terminate = stub();

Expand Down

0 comments on commit 2f85c6c

Please sign in to comment.