Skip to content

Commit

Permalink
Fix checks
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubra89 committed Jun 12, 2022
1 parent d5dcf4f commit db28285
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/factories/createLightship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export default async (userConfiguration?: ConfigurationInput): Promise<Lightship
return serverIsReady;
};

const app = createFastify({ exposeHeadRoutes: true });
const app = createFastify({
exposeHeadRoutes: true,
});

app.addHook('onError', (request, reply, error, done) => {
// Only send Sentry errors when not in development
Expand Down
44 changes: 25 additions & 19 deletions test/lightship/factories/createLightship.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,28 @@ const getLightshipPort = (lightship: Lightship) => {
return address.port;
};

function getServiceState(lightship: Lightship, method: 'GET'): Promise<ServiceState>;
function getServiceState(lightship: Lightship, method: 'HEAD'): Promise<ServiceState<Pick<ProbeState, 'status'>>>;
async function getServiceState(lightship: Lightship, method: 'GET' | 'HEAD'): Promise<ServiceState<ProbeState | Pick<ProbeState, 'status'>>> {

function getServiceState (lightship: Lightship, method: 'GET'): Promise<ServiceState>;
function getServiceState (lightship: Lightship, method: 'HEAD'): Promise<ServiceState<Pick<ProbeState, 'status'>>>;
async function getServiceState (lightship: Lightship, method: 'GET' | 'HEAD'): Promise<ServiceState<Pick<ProbeState, 'status'> | ProbeState>> {
const port = getLightshipPort(lightship);
const baseURL = `http://127.0.0.1:${port}`
const baseAxios = axios.create({ baseURL, validateStatus: () => true, method })
const baseURL = `http://127.0.0.1:${port}`;
const baseAxios = axios.create({
baseURL,
method,
validateStatus: () => {
return true;
},
});

const [health, live, ready] = await Promise.all([
const [
health,
live,
ready,
] = await Promise.all([
baseAxios('/health'),
baseAxios('/live'),
baseAxios('/ready'),
])
]);

if (method === 'GET') {
return {
Expand All @@ -67,19 +76,17 @@ async function getServiceState(lightship: Lightship, method: 'GET' | 'HEAD'): Pr
} else {
return {
health: {
status: health.status
status: health.status,
},
live: {
status: live.status,
},
ready: {
status: ready.status,
},
}
};
}


};
}

test('server starts in SERVER_IS_NOT_READY state', async (t) => {
const terminate = stub();
Expand Down Expand Up @@ -147,13 +154,12 @@ test('server responds to HEAD requests', async (t) => {

lightship.signalReady();

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

t.is(state.health.status, 200)
t.is(state.health.status, 200)
t.is(state.health.status, 200)

})
t.is(state.health.status, 200);
t.is(state.health.status, 200);
t.is(state.health.status, 200);
});

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

0 comments on commit db28285

Please sign in to comment.