chore: added some more mock defintions and refactoring the TaskManager.forPlugin
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -14,3 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
export { mockTokenManagerFactory } from './mockTokenManagerService';
|
||||
export { mockConfigFactory } from './mockConfigService';
|
||||
export { mockDatabaseFactory } from './mockDatabaseService';
|
||||
export { mockDiscoveryFactory } from './mockDiscoveryService';
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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 {
|
||||
coreServices,
|
||||
createServiceFactory,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { AppConfig, ConfigReader } from '@backstage/config';
|
||||
|
||||
/** @public */
|
||||
export const mockConfigFactory = createServiceFactory({
|
||||
service: coreServices.config,
|
||||
deps: {},
|
||||
async factory(_, options?: { config?: AppConfig }) {
|
||||
return new ConfigReader(options?.config);
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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());
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2023 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 { SingleHostDiscovery } from '@backstage/backend-common';
|
||||
import {
|
||||
coreServices,
|
||||
createServiceFactory,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
|
||||
/** @public */
|
||||
export const mockDiscoveryFactory = createServiceFactory({
|
||||
service: coreServices.discovery,
|
||||
deps: {},
|
||||
async factory() {
|
||||
// todo(blam): we want to grab the port from the httpRouter when that's available here
|
||||
// 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' },
|
||||
}),
|
||||
);
|
||||
|
||||
return async () => {
|
||||
return discovery;
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -21,10 +21,7 @@ import {
|
||||
rootLifecycleFactory,
|
||||
loggerFactory,
|
||||
rootLoggerFactory,
|
||||
configFactory,
|
||||
discoveryFactory,
|
||||
cacheFactory,
|
||||
databaseFactory,
|
||||
permissionsFactory,
|
||||
schedulerFactory,
|
||||
urlReaderFactory,
|
||||
@@ -38,7 +35,12 @@ import {
|
||||
ExtensionPoint,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
|
||||
import { mockTokenManagerFactory } from '../implementations';
|
||||
import {
|
||||
mockConfigFactory,
|
||||
mockDatabaseFactory,
|
||||
mockTokenManagerFactory,
|
||||
mockDiscoveryFactory,
|
||||
} from '../implementations';
|
||||
|
||||
/** @alpha */
|
||||
export interface TestBackendOptions<
|
||||
@@ -66,9 +68,9 @@ export interface TestBackendOptions<
|
||||
|
||||
const defaultServiceFactories = [
|
||||
cacheFactory(),
|
||||
configFactory(),
|
||||
databaseFactory(),
|
||||
discoveryFactory(),
|
||||
mockConfigFactory(),
|
||||
mockDatabaseFactory(),
|
||||
mockDiscoveryFactory(),
|
||||
lifecycleFactory(),
|
||||
loggerFactory(),
|
||||
permissionsFactory(),
|
||||
|
||||
Reference in New Issue
Block a user