Merge pull request #13370 from RoadieHQ/fix-persisting-refresh-keys
fix: return refresh keys if item is cached
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-backend': patch
|
||||
---
|
||||
|
||||
Fixes a bug to be able to utilize refresh keys after the entity is loaded from cache
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
CatalogProcessorCache,
|
||||
CatalogProcessorEntityResult,
|
||||
CatalogProcessorErrorResult,
|
||||
CatalogProcessorRefreshKeysResult,
|
||||
CatalogProcessorResult,
|
||||
} from '@backstage/plugin-catalog-node';
|
||||
import { defaultEntityDataParser } from '../util/parse';
|
||||
@@ -127,19 +128,25 @@ describe('UrlReaderProcessor', () => {
|
||||
mockCache.get.mockResolvedValue(cacheItem);
|
||||
const processor = new UrlReaderProcessor({ reader, logger });
|
||||
|
||||
const generated = (await new Promise<CatalogProcessorResult>(emit =>
|
||||
processor.readLocation(
|
||||
spec,
|
||||
false,
|
||||
emit,
|
||||
defaultEntityDataParser,
|
||||
mockCache,
|
||||
),
|
||||
)) as CatalogProcessorEntityResult;
|
||||
const emitted = new Array<CatalogProcessorResult>();
|
||||
await processor.readLocation(
|
||||
spec,
|
||||
false,
|
||||
r => emitted.push(r),
|
||||
defaultEntityDataParser,
|
||||
mockCache,
|
||||
);
|
||||
|
||||
const entity = emitted[0] as CatalogProcessorEntityResult;
|
||||
const refresh = emitted[1] as CatalogProcessorRefreshKeysResult;
|
||||
|
||||
expect(entity.type).toBe('entity');
|
||||
expect(entity.location).toEqual(spec);
|
||||
expect(entity.entity).toEqual({ mock: 'entity' });
|
||||
|
||||
expect(refresh.type).toBe('refresh');
|
||||
expect(refresh.key).toBe('url:http://localhost/component.yaml');
|
||||
|
||||
expect(generated.type).toBe('entity');
|
||||
expect(generated.location).toEqual(spec);
|
||||
expect(generated.entity).toEqual({ mock: 'entity' });
|
||||
expect(mockCache.get).toBeCalledWith('v1');
|
||||
expect(mockCache.get).toBeCalledTimes(1);
|
||||
expect(mockCache.set).toBeCalledTimes(0);
|
||||
|
||||
@@ -102,6 +102,7 @@ export class UrlReaderProcessor implements CatalogProcessor {
|
||||
for (const parseResult of cacheItem.value) {
|
||||
emit(parseResult);
|
||||
}
|
||||
emit(processingResult.refresh(`${location.type}:${location.target}`));
|
||||
} else if (error.name === 'NotFoundError') {
|
||||
if (!optional) {
|
||||
emit(processingResult.notFoundError(location, message));
|
||||
|
||||
Reference in New Issue
Block a user