add and fix tests

Signed-off-by: Kiss Miklos <miklos@roadie.io>
This commit is contained in:
Kiss Miklos
2022-07-01 17:21:47 +02:00
parent b79a82028a
commit 197ed5b83c
7 changed files with 44 additions and 8 deletions
@@ -89,8 +89,9 @@ describe('FileReaderProcessor', () => {
type: 'file',
target: expect.stringMatching(/^[^*]*$/),
});
expect(emit.mock.calls[1][0].entityRef).toEqual(
'component:default/component-test',
expect(emit.mock.calls[1][0].key).toContain('file:');
expect(emit.mock.calls[1][0].key).toContain(
'fileReaderProcessor/component.yaml',
);
expect(emit.mock.calls[2][0].entity).toEqual({
kind: 'API',
@@ -17,6 +17,7 @@ import { UrlReader } from '@backstage/backend-common';
import { Entity } from '@backstage/catalog-model';
import { ConfigReader } from '@backstage/config';
import { ScmIntegrations } from '@backstage/integration';
import { CatalogProcessorResult } from '../../api';
import {
jsonPlaceholderResolver,
PlaceholderProcessor,
@@ -357,6 +358,36 @@ describe('PlaceholderProcessor', () => {
expect(read).not.toBeCalled();
});
it('should emit the resolverValue as a refreshKey', async () => {
read.mockResolvedValue(
Buffer.from(JSON.stringify({ a: ['b', 7] }), 'utf-8'),
);
const processor = new PlaceholderProcessor({
resolvers: {
json: jsonPlaceholderResolver,
},
reader,
integrations,
});
const emitted = new Array<CatalogProcessorResult>();
await processor.preProcessEntity(
{
apiVersion: 'a',
kind: 'k',
metadata: { name: 'n' },
spec: { a: [{ b: { $json: './path-to-file.json' } }] },
},
{ type: 'fake', target: 'http://example.com' },
result => emitted.push(result),
);
console.log(emitted);
expect(emitted[0]).toEqual({
type: 'refresh',
key: 'url:./path-to-file.json',
});
});
});
describe('yamlPlaceholderResolver', () => {
@@ -86,6 +86,10 @@ describe('UrlReaderProcessor', () => {
location: spec,
entity: { kind: 'component', metadata: { name: 'mock-url-entity' } },
});
expect(emitted[1]).toEqual({
type: 'refresh',
key: 'url:http://localhost/component.yaml',
});
expect(mockCache.set).toBeCalledWith('v1', {
etag: 'my-etag',
value: [
@@ -49,7 +49,7 @@ export class AuthorizedRefreshService implements RefreshService {
}
await this.service.refresh(options);
}
async refreshByRefreshKey(options: RefreshByRefreshKeysOptions) {
await this.service.refreshByRefreshKey(options);
async refreshByRefreshKeys(options: RefreshByRefreshKeysOptions) {
await this.service.refreshByRefreshKeys(options);
}
}
@@ -49,7 +49,7 @@ export class DefaultRefreshService implements RefreshService {
});
});
}
async refreshByRefreshKey(options: RefreshByRefreshKeysOptions) {
async refreshByRefreshKeys(options: RefreshByRefreshKeysOptions) {
await this.database.transaction(async tx => {
await this.database.refreshByRefreshKeys(tx, options);
});
@@ -57,7 +57,7 @@ describe('createRouter readonly disabled', () => {
listLocations: jest.fn(),
deleteLocation: jest.fn(),
};
refreshService = { refresh: jest.fn(), refreshByRefreshKey: jest.fn() };
refreshService = { refresh: jest.fn(), refreshByRefreshKeys: jest.fn() };
orchestrator = { process: jest.fn() };
const router = await createRouter({
entitiesCatalog,
@@ -712,7 +712,7 @@ describe('NextRouter permissioning', () => {
listLocations: jest.fn(),
deleteLocation: jest.fn(),
};
refreshService = { refresh: jest.fn(), refreshByRefreshKey: jest.fn() };
refreshService = { refresh: jest.fn(), refreshByRefreshKeys: jest.fn() };
const router = await createRouter({
entitiesCatalog,
locationService,
+1 -1
View File
@@ -74,7 +74,7 @@ export interface RefreshService {
* Request a refresh of entities in the catalog.
*/
refresh(options: RefreshOptions): Promise<void>;
refreshByRefreshKey(options: RefreshByRefreshKeysOptions): Promise<void>;
refreshByRefreshKeys(options: RefreshByRefreshKeysOptions): Promise<void>;
}
/**