chore: rebase/combine tests
Co-authored-by: Fredrik Adelöw <freben@gmail.com> Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
+49
-55
@@ -18,16 +18,12 @@ import { getVoidLogger } from '@backstage/backend-common';
|
||||
import {
|
||||
Entity,
|
||||
EntityPolicies,
|
||||
EntityPolicy,
|
||||
LocationEntity,
|
||||
LocationSpec,
|
||||
LOCATION_ANNOTATION,
|
||||
ORIGIN_LOCATION_ANNOTATION,
|
||||
} from '@backstage/catalog-model';
|
||||
import {
|
||||
ScmIntegrationRegistry,
|
||||
ScmIntegrations,
|
||||
} from '@backstage/integration';
|
||||
import { ScmIntegrations } from '@backstage/integration';
|
||||
import {
|
||||
CatalogProcessor,
|
||||
CatalogProcessorCache,
|
||||
@@ -79,7 +75,7 @@ class FooBarProcessor implements CatalogProcessor {
|
||||
}
|
||||
|
||||
describe('DefaultCatalogProcessingOrchestrator', () => {
|
||||
describe('2', () => {
|
||||
describe('basic processing', () => {
|
||||
const entity = {
|
||||
apiVersion: 'my-api/v1',
|
||||
kind: 'FooBar',
|
||||
@@ -92,17 +88,13 @@ describe('DefaultCatalogProcessingOrchestrator', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const rulesEnforcer: CatalogRulesEnforcer = {
|
||||
isAllowed: () => true,
|
||||
};
|
||||
|
||||
const orchestrator = new DefaultCatalogProcessingOrchestrator({
|
||||
processors: [new FooBarProcessor()],
|
||||
integrations: ScmIntegrations.fromConfig(new ConfigReader({})),
|
||||
logger: getVoidLogger(),
|
||||
parser: defaultEntityDataParser,
|
||||
policy: EntityPolicies.allOf([]),
|
||||
rulesEnforcer,
|
||||
rulesEnforcer: { isAllowed: () => true },
|
||||
});
|
||||
|
||||
it('runs a minimal processing', async () => {
|
||||
@@ -196,53 +188,55 @@ describe('DefaultCatalogProcessingOrchestrator', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('enforces catalog rules', async () => {
|
||||
const entity: LocationEntity = {
|
||||
apiVersion: 'backstage.io/v1beta1',
|
||||
kind: 'Location',
|
||||
metadata: {
|
||||
name: 'l',
|
||||
annotations: {
|
||||
[ORIGIN_LOCATION_ANNOTATION]: 'url:https://example.com/origin.yaml',
|
||||
[LOCATION_ANNOTATION]: 'url:https://example.com/origin.yaml',
|
||||
describe('rules', () => {
|
||||
it('enforces catalog rules', async () => {
|
||||
const entity: LocationEntity = {
|
||||
apiVersion: 'backstage.io/v1beta1',
|
||||
kind: 'Location',
|
||||
metadata: {
|
||||
name: 'l',
|
||||
annotations: {
|
||||
[ORIGIN_LOCATION_ANNOTATION]: 'url:https://example.com/origin.yaml',
|
||||
[LOCATION_ANNOTATION]: 'url:https://example.com/origin.yaml',
|
||||
},
|
||||
},
|
||||
},
|
||||
spec: {
|
||||
type: 'url',
|
||||
target: 'http://example.com/entity.yaml',
|
||||
},
|
||||
};
|
||||
spec: {
|
||||
type: 'url',
|
||||
target: 'http://example.com/entity.yaml',
|
||||
},
|
||||
};
|
||||
|
||||
const integrations = ScmIntegrations.fromConfig(new ConfigReader({}));
|
||||
const processor: jest.Mocked<CatalogProcessor> = {
|
||||
validateEntityKind: jest.fn(async () => true),
|
||||
readLocation: jest.fn(async (_l, _o, emit) => {
|
||||
emit(results.entity({ type: 't', target: 't' }, entity));
|
||||
return true;
|
||||
}),
|
||||
};
|
||||
const parser: CatalogProcessorParser = jest.fn();
|
||||
const rulesEnforcer: jest.Mocked<CatalogRulesEnforcer> = {
|
||||
isAllowed: jest.fn(),
|
||||
};
|
||||
const integrations = ScmIntegrations.fromConfig(new ConfigReader({}));
|
||||
const processor: jest.Mocked<CatalogProcessor> = {
|
||||
validateEntityKind: jest.fn(async () => true),
|
||||
readLocation: jest.fn(async (_l, _o, emit) => {
|
||||
emit(results.entity({ type: 't', target: 't' }, entity));
|
||||
return true;
|
||||
}),
|
||||
};
|
||||
const parser: CatalogProcessorParser = jest.fn();
|
||||
const rulesEnforcer: jest.Mocked<CatalogRulesEnforcer> = {
|
||||
isAllowed: jest.fn(),
|
||||
};
|
||||
|
||||
const orchestrator = new DefaultCatalogProcessingOrchestrator({
|
||||
processors: [processor],
|
||||
integrations,
|
||||
logger: getVoidLogger(),
|
||||
parser,
|
||||
policy: EntityPolicies.allOf([]),
|
||||
rulesEnforcer,
|
||||
const orchestrator = new DefaultCatalogProcessingOrchestrator({
|
||||
processors: [processor],
|
||||
integrations,
|
||||
logger: getVoidLogger(),
|
||||
parser,
|
||||
policy: EntityPolicies.allOf([]),
|
||||
rulesEnforcer,
|
||||
});
|
||||
|
||||
rulesEnforcer.isAllowed.mockReturnValueOnce(true);
|
||||
await expect(
|
||||
orchestrator.process({ entity, state: {} }),
|
||||
).resolves.toEqual(expect.objectContaining({ ok: true }));
|
||||
|
||||
rulesEnforcer.isAllowed.mockReturnValueOnce(false);
|
||||
await expect(
|
||||
orchestrator.process({ entity, state: {} }),
|
||||
).resolves.toEqual(expect.objectContaining({ ok: false }));
|
||||
});
|
||||
|
||||
rulesEnforcer.isAllowed.mockReturnValueOnce(true);
|
||||
await expect(orchestrator.process({ entity, state: {} })).resolves.toEqual(
|
||||
expect.objectContaining({ ok: true }),
|
||||
);
|
||||
|
||||
rulesEnforcer.isAllowed.mockReturnValueOnce(false);
|
||||
await expect(orchestrator.process({ entity, state: {} })).resolves.toEqual(
|
||||
expect.objectContaining({ ok: false }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user