backend-defaults,test-utils: use, export, and test health service
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -242,6 +242,15 @@ describe('TestBackend', () => {
|
||||
expect(res.body).toEqual({ message: 'pong' });
|
||||
});
|
||||
|
||||
it('should expose health check endpoints', async () => {
|
||||
const { server } = await startTestBackend({ features: [] });
|
||||
|
||||
const res = await request(server).get('/.backstage/health/v1/liveness');
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.body).toEqual({ status: 'ok' });
|
||||
});
|
||||
|
||||
it('should provide extension point implementations', async () => {
|
||||
expect.assertions(3);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import express from 'express';
|
||||
// Direct internal import to avoid duplication
|
||||
// eslint-disable-next-line @backstage/no-forbidden-package-imports
|
||||
import { InternalBackendFeature } from '@backstage/backend-plugin-api/src/wiring/types';
|
||||
import { createHealthRouter } from '@backstage/backend-defaults/rootHttpRouter';
|
||||
|
||||
/** @public */
|
||||
export interface TestBackendOptions<TExtensionPoints extends any[]> {
|
||||
@@ -73,6 +74,7 @@ export const defaultServiceFactories = [
|
||||
mockServices.lifecycle.factory(),
|
||||
mockServices.logger.factory(),
|
||||
mockServices.permissions.factory(),
|
||||
mockServices.rootHealth.factory(),
|
||||
mockServices.rootLifecycle.factory(),
|
||||
mockServices.rootLogger.factory(),
|
||||
mockServices.scheduler.factory(),
|
||||
@@ -251,15 +253,18 @@ export async function startTestBackend<TExtensionPoints extends any[]>(
|
||||
config: coreServices.rootConfig,
|
||||
lifecycle: coreServices.rootLifecycle,
|
||||
rootLogger: coreServices.rootLogger,
|
||||
health: coreServices.rootHealth,
|
||||
},
|
||||
async factory({ config, lifecycle, rootLogger }) {
|
||||
async factory({ config, lifecycle, rootLogger, health }) {
|
||||
const router = DefaultRootHttpRouter.create();
|
||||
const logger = rootLogger.child({ service: 'rootHttpRouter' });
|
||||
|
||||
const app = express();
|
||||
|
||||
const middleware = MiddlewareFactory.create({ config, logger });
|
||||
const healthRouter = createHealthRouter({ health });
|
||||
|
||||
app.use(healthRouter);
|
||||
app.use(router.handler());
|
||||
app.use(middleware.notFound());
|
||||
app.use(middleware.error());
|
||||
|
||||
Reference in New Issue
Block a user