1. Remove DiscoveryApi (frontend) and use PluginEndpointDiscovery(SingleHostDiscovery) (backend)
2. Mock class for testing
This commit is contained in:
@@ -17,8 +17,10 @@
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
import fs from 'fs-extra';
|
||||
import path from 'path';
|
||||
import { getVoidLogger, SingleHostDiscovery } from '@backstage/backend-common';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import {
|
||||
getVoidLogger,
|
||||
PluginEndpointDiscovery,
|
||||
} from '@backstage/backend-common';
|
||||
import { LocalPublish } from './local';
|
||||
|
||||
const createMockEntity = (annotations = {}) => {
|
||||
@@ -38,20 +40,11 @@ const logger = getVoidLogger();
|
||||
|
||||
describe('local publisher', () => {
|
||||
it('should publish generated documentation dir', async () => {
|
||||
const testConfig = ConfigReader.fromConfigs([
|
||||
{
|
||||
context: '',
|
||||
data: {
|
||||
backend: {
|
||||
baseUrl: 'http://localhost:7000',
|
||||
listen: {
|
||||
port: 7000,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
const testDiscovery = SingleHostDiscovery.fromConfig(testConfig);
|
||||
const testDiscovery: jest.Mocked<PluginEndpointDiscovery> = {
|
||||
getBaseUrl: jest.fn().mockResolvedValueOnce('http://localhost:7000'),
|
||||
getExternalBaseUrl: jest.fn(),
|
||||
};
|
||||
|
||||
const publisher = new LocalPublish(logger, testDiscovery);
|
||||
|
||||
const mockEntity = createMockEntity();
|
||||
|
||||
@@ -17,16 +17,18 @@ import fs from 'fs-extra';
|
||||
import { Logger } from 'winston';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
import { PublisherBase } from './types';
|
||||
import { resolvePackagePath } from '@backstage/backend-common';
|
||||
import { DiscoveryApi } from '@backstage/core-api';
|
||||
import {
|
||||
resolvePackagePath,
|
||||
PluginEndpointDiscovery,
|
||||
} from '@backstage/backend-common';
|
||||
|
||||
export class LocalPublish implements PublisherBase {
|
||||
private readonly logger: Logger;
|
||||
private readonly discoveryApi: DiscoveryApi;
|
||||
private readonly discovery: PluginEndpointDiscovery;
|
||||
|
||||
constructor(logger: Logger, discoveryApi: DiscoveryApi) {
|
||||
constructor(logger: Logger, discovery: PluginEndpointDiscovery) {
|
||||
this.logger = logger;
|
||||
this.discoveryApi = discoveryApi;
|
||||
this.discovery = discovery;
|
||||
}
|
||||
|
||||
publish({
|
||||
@@ -66,7 +68,7 @@ export class LocalPublish implements PublisherBase {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
this.discoveryApi.getBaseUrl('techdocs').then(techdocsApiUrl => {
|
||||
this.discovery.getBaseUrl('techdocs').then(techdocsApiUrl => {
|
||||
resolve({
|
||||
remoteUrl: `${techdocsApiUrl}/static/docs/${entity.metadata.name}`,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user