modify ends with .yaml check to contains .yaml

This commit is contained in:
Omer Farooq
2020-08-23 14:26:39 +12:00
parent 54b6a9cc06
commit f57f6a7402
6 changed files with 23 additions and 8 deletions
@@ -16,7 +16,7 @@
import { AzureApiReaderProcessor } from './AzureApiReaderProcessor';
describe('BitbucketApiReaderProcessor', () => {
describe('AzureApiReaderProcessor', () => {
it('should build raw api', () => {
const processor = new AzureApiReaderProcessor();
const tests = [
@@ -51,6 +51,22 @@ describe('YamlProcessor', () => {
expect(never).not.toBeCalled();
});
it('should process url that contains yaml', async () => {
const containsYamlLocationSpec = {
type: 'url',
target: 'http://example.com/component?path=test.yaml&c=1&d=2',
};
const buffer = Buffer.from([]);
const emit = jest.fn();
expect(
await processor.parseData(buffer, containsYamlLocationSpec, emit),
).toBe(true);
expect(emit).toBeCalled();
});
it('should process entity with yaml', async () => {
const entity = {
apiVersion: 'backstage.io/v1alpha1',
@@ -26,7 +26,7 @@ export class YamlProcessor implements LocationProcessor {
location: LocationSpec,
emit: LocationProcessorEmit,
): Promise<boolean> {
if (!location.target.match(/\.ya?ml$/)) {
if (!location.target.match(/\.ya?ml/)) {
return false;
}
@@ -86,9 +86,7 @@ const RegisterComponentPage: FC<{}> = () => {
{ url: /.*/, type: 'github' },
];
const type = typeMapping.filter(item => {
return new RegExp(item.url).test(target);
})[0].type;
const type = typeMapping.filter(item => item.url.test(target))[0].type;
const data = await catalogApi.addLocation(type, target);
@@ -31,11 +31,12 @@ describe('ComponentIdValidators', () => {
});
});
describe('yamlValidator', () => {
const errorMessage = "Must end with '.yaml'.";
const errorMessage = "Must contain '.yaml'.";
test.each([
[true, '.yaml'],
[true, 'http://example.com/blob/master/service.yaml'],
[true, 'https://example.yaml'],
[true, 'https://example.com?path=abc.yaml&c=1'],
[errorMessage, '.yml'],
[errorMessage, 'http://example.com/blob/master/service'],
[errorMessage, undefined],
@@ -19,6 +19,6 @@ export const ComponentIdValidators = {
(typeof value === 'string' && value.match(/^https:\/\//) !== null) ||
'Must start with https://.',
yamlValidator: (value: any) =>
(typeof value === 'string' && value.match(/.yaml$/) !== null) ||
"Must end with '.yaml'.",
(typeof value === 'string' && value.match(/.yaml/) !== null) ||
"Must contain '.yaml'.",
};