chore: reworking how we do the TaskScheduler for now

Signed-off-by: blam <ben@blam.sh>

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
blam
2023-01-04 16:31:29 +01:00
parent 9ec23f2d7c
commit 875cd848fd
8 changed files with 51 additions and 70 deletions
@@ -15,5 +15,4 @@
*/
export { mockTokenManagerFactory } from './mockTokenManagerService';
export { mockConfigFactory } from './mockConfigService';
export { mockDatabaseFactory } from './mockDatabaseService';
export { mockDiscoveryFactory } from './mockDiscoveryService';
@@ -1,46 +0,0 @@
/*
* Copyright 2022 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { DatabaseManager } from '@backstage/backend-common';
import {
coreServices,
createServiceFactory,
} from '@backstage/backend-plugin-api';
import { ConfigReader } from '@backstage/config';
/** @public */
export const mockDatabaseFactory = createServiceFactory({
service: coreServices.database,
deps: {
config: coreServices.config,
plugin: coreServices.pluginMetadata,
},
async factory({ config }) {
const databaseManager = config.getOptional('backend.database')
? DatabaseManager.fromConfig(config)
: DatabaseManager.fromConfig(
new ConfigReader({
backend: {
database: { client: 'better-sqlite', connection: ':memory:' },
},
}),
);
return async ({ plugin }) => {
return databaseManager.forPlugin(plugin.getId());
};
},
});
@@ -29,7 +29,7 @@ export const mockDiscoveryFactory = createServiceFactory({
// to provide a better way to create our mockDiscoveryService.
const discovery = SingleHostDiscovery.fromConfig(
new ConfigReader({
backend: { baseUrl: 'http://localhost:7000', listen: '0.0.0.0:7000' },
backend: { baseUrl: 'http://localhost:7007', listen: '0.0.0.0' },
}),
);
@@ -171,9 +171,12 @@ describe('TestBackend', () => {
config: coreServices.config,
database: coreServices.database,
discovery: coreServices.discovery,
httpRouter: coreServices.httpRouter,
lifecycle: coreServices.lifecycle,
logger: coreServices.logger,
permissions: coreServices.permissions,
pluginMetadata: coreServices.pluginMetadata,
rootHttpRouter: coreServices.rootHttpRouter,
rootLifecycle: coreServices.rootLifecycle,
rootLogger: coreServices.rootLogger,
scheduler: coreServices.scheduler,
@@ -181,7 +184,7 @@ describe('TestBackend', () => {
urlReader: coreServices.urlReader,
},
async init(deps) {
expect(Object.keys(deps)).toHaveLength(12);
expect(Object.keys(deps)).toHaveLength(14);
expect(Object.values(deps)).not.toContain(undefined);
},
});
@@ -25,6 +25,9 @@ import {
permissionsFactory,
schedulerFactory,
urlReaderFactory,
databaseFactory,
rootHttpRouterFactory,
httpRouterFactory,
} from '@backstage/backend-app-api';
import {
@@ -37,7 +40,6 @@ import {
import {
mockConfigFactory,
mockDatabaseFactory,
mockTokenManagerFactory,
mockDiscoveryFactory,
} from '../implementations';
@@ -68,16 +70,18 @@ export interface TestBackendOptions<
const defaultServiceFactories = [
cacheFactory(),
mockConfigFactory(),
mockDatabaseFactory(),
mockDiscoveryFactory(),
databaseFactory(),
httpRouterFactory(),
lifecycleFactory(),
loggerFactory(),
mockConfigFactory(),
mockDiscoveryFactory(),
mockTokenManagerFactory(),
permissionsFactory(),
rootHttpRouterFactory(),
rootLifecycleFactory(),
rootLoggerFactory(),
schedulerFactory(),
mockTokenManagerFactory(),
urlReaderFactory(),
];