Merge pull request #16203 from backstage/rugvip/ref
backend-test-utils: remove mock service refs
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-test-utils': patch
|
||||
---
|
||||
|
||||
Added explicit return type signature for `mockServices.config()`.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-test-utils': patch
|
||||
---
|
||||
|
||||
Removed the `ref` from all `mockServices`.
|
||||
@@ -6,7 +6,6 @@
|
||||
import { Backend } from '@backstage/backend-app-api';
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { CacheService } from '@backstage/backend-plugin-api';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { ConfigService } from '@backstage/backend-plugin-api';
|
||||
import { DatabaseService } from '@backstage/backend-plugin-api';
|
||||
import { ExtendedHttpServer } from '@backstage/backend-app-api';
|
||||
@@ -20,7 +19,6 @@ import { LifecycleService } from '@backstage/backend-plugin-api';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { PermissionsService } from '@backstage/backend-plugin-api';
|
||||
import { RootLifecycleService } from '@backstage/backend-plugin-api';
|
||||
import { RootLoggerService } from '@backstage/backend-plugin-api';
|
||||
import { SchedulerService } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
@@ -34,35 +32,27 @@ export function isDockerDisabledForTests(): boolean;
|
||||
export namespace mockServices {
|
||||
// (undocumented)
|
||||
export namespace cache {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<CacheService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<CacheService>;
|
||||
}
|
||||
// (undocumented)
|
||||
export function config(options?: config.Options): ConfigReader;
|
||||
export function config(options?: config.Options): ConfigService;
|
||||
// (undocumented)
|
||||
export namespace config {
|
||||
// (undocumented)
|
||||
export type Options = {
|
||||
data?: JsonObject;
|
||||
};
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<ConfigService, 'root'>;
|
||||
const // (undocumented)
|
||||
factory: (options?: Options | undefined) => ServiceFactory<ConfigService>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace database {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<DatabaseService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<DatabaseService>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace httpRouter {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<HttpRouterService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: (
|
||||
options?: HttpRouterFactoryOptions | undefined,
|
||||
@@ -72,36 +62,26 @@ export namespace mockServices {
|
||||
export function identity(): IdentityService;
|
||||
// (undocumented)
|
||||
export namespace identity {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<IdentityService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<IdentityService>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace lifecycle {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<LifecycleService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<LifecycleService>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace logger {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<LoggerService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<LoggerService>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace permissions {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<PermissionsService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<PermissionsService>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace rootLifecycle {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<RootLifecycleService, 'root'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<RootLifecycleService>;
|
||||
}
|
||||
@@ -120,15 +100,11 @@ export namespace mockServices {
|
||||
debug: boolean;
|
||||
};
|
||||
};
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<RootLoggerService, 'root'>;
|
||||
const // (undocumented)
|
||||
factory: (options?: Options | undefined) => ServiceFactory<LoggerService>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace scheduler {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<SchedulerService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<SchedulerService>;
|
||||
}
|
||||
@@ -136,15 +112,11 @@ export namespace mockServices {
|
||||
export function tokenManager(): TokenManagerService;
|
||||
// (undocumented)
|
||||
export namespace tokenManager {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<TokenManagerService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<TokenManagerService>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace urlReader {
|
||||
const // (undocumented)
|
||||
ref: ServiceRef<UrlReaderService, 'plugin'>;
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<UrlReaderService>;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
ConfigService,
|
||||
coreServices,
|
||||
createServiceFactory,
|
||||
IdentityService,
|
||||
@@ -56,14 +57,13 @@ function simpleFactory<TService, TOptions extends [options?: object] = []>(
|
||||
* @alpha
|
||||
*/
|
||||
export namespace mockServices {
|
||||
export function config(options?: config.Options) {
|
||||
export function config(options?: config.Options): ConfigService {
|
||||
return new ConfigReader(options?.data, 'mock-config');
|
||||
}
|
||||
export namespace config {
|
||||
export type Options = { data?: JsonObject };
|
||||
|
||||
export const ref = coreServices.config;
|
||||
export const factory = simpleFactory(ref, config);
|
||||
export const factory = simpleFactory(coreServices.config, config);
|
||||
}
|
||||
|
||||
export function rootLogger(options?: rootLogger.Options): LoggerService {
|
||||
@@ -76,8 +76,7 @@ export namespace mockServices {
|
||||
| { error: boolean; warn: boolean; info: boolean; debug: boolean };
|
||||
};
|
||||
|
||||
export const ref = coreServices.rootLogger;
|
||||
export const factory = simpleFactory(ref, rootLogger);
|
||||
export const factory = simpleFactory(coreServices.rootLogger, rootLogger);
|
||||
}
|
||||
|
||||
export function tokenManager(): TokenManagerService {
|
||||
@@ -93,55 +92,47 @@ export namespace mockServices {
|
||||
};
|
||||
}
|
||||
export namespace tokenManager {
|
||||
export const ref = coreServices.tokenManager;
|
||||
export const factory = simpleFactory(ref, tokenManager);
|
||||
export const factory = simpleFactory(
|
||||
coreServices.tokenManager,
|
||||
tokenManager,
|
||||
);
|
||||
}
|
||||
|
||||
export function identity(): IdentityService {
|
||||
return new MockIdentityService();
|
||||
}
|
||||
export namespace identity {
|
||||
export const ref = coreServices.identity;
|
||||
export const factory = simpleFactory(ref, identity);
|
||||
export const factory = simpleFactory(coreServices.identity, identity);
|
||||
}
|
||||
|
||||
// TODO(Rugvip): Not all core services have implementations available here yet.
|
||||
// some may need a bit more refactoring for it to be simpler to
|
||||
// re-implement functioning mock versions here.
|
||||
export namespace cache {
|
||||
export const ref = coreServices.cache;
|
||||
export const factory = cacheFactory;
|
||||
}
|
||||
export namespace database {
|
||||
export const ref = coreServices.database;
|
||||
export const factory = databaseFactory;
|
||||
}
|
||||
export namespace httpRouter {
|
||||
export const ref = coreServices.httpRouter;
|
||||
export const factory = httpRouterFactory;
|
||||
}
|
||||
export namespace lifecycle {
|
||||
export const ref = coreServices.lifecycle;
|
||||
export const factory = lifecycleFactory;
|
||||
}
|
||||
export namespace logger {
|
||||
export const ref = coreServices.logger;
|
||||
export const factory = loggerFactory;
|
||||
}
|
||||
export namespace permissions {
|
||||
export const ref = coreServices.permissions;
|
||||
export const factory = permissionsFactory;
|
||||
}
|
||||
export namespace rootLifecycle {
|
||||
export const ref = coreServices.rootLifecycle;
|
||||
export const factory = rootLifecycleFactory;
|
||||
}
|
||||
export namespace scheduler {
|
||||
export const ref = coreServices.scheduler;
|
||||
export const factory = schedulerFactory;
|
||||
}
|
||||
export namespace urlReader {
|
||||
export const ref = coreServices.urlReader;
|
||||
export const factory = urlReaderFactory;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user