removed getRawBody with buffer, changed back depricatedTypes in config index and removed integration test

Signed-off-by: Simon <simme.jakobsson@gmail.com>
This commit is contained in:
Simon
2022-11-16 21:52:19 +01:00
parent 772197efaf
commit d01640d494
6 changed files with 13 additions and 185 deletions
@@ -247,10 +247,11 @@ describe('AwsS3UrlReader', () => {
});
it('returns contents of an object in a bucket', async () => {
const response = await reader.readUrl(
const { buffer } = await reader.readUrl(
'https://test-bucket.s3.us-east-2.amazonaws.com/awsS3-mock-object.yaml',
);
const fromStream = await getRawBody(response.stream!());
const response = buffer();
const fromStream = await response;
expect(fromStream.toString().trim()).toBe('site_name: Test');
});
@@ -116,9 +116,9 @@ describe('AzureUrlReader', () => {
logger,
treeResponseFactory,
});
const data = await reader.readUrl(url);
const fromStream = await getRawBody(data.stream!());
const { buffer } = await reader.readUrl(url);
const fromStream = await buffer();
const res = await JSON.parse(fromStream.toString());
expect(res).toEqual(response);
});
@@ -22,7 +22,6 @@ import { setupServer } from 'msw/node';
import { getVoidLogger } from '../logging';
import { FetchUrlReader } from './FetchUrlReader';
import { DefaultReadTreeResponseFactory } from './tree';
import getRawBody from 'raw-body';
const fetchUrlReader = new FetchUrlReader();
@@ -172,11 +171,12 @@ describe('FetchUrlReader', () => {
describe('read', () => {
it('should return etag from the response', async () => {
const buffer = await fetchUrlReader.readUrl(
const { buffer } = await fetchUrlReader.readUrl(
'https://backstage.io/some-resource',
);
const fromStream = await getRawBody(buffer.stream!());
expect(fromStream.toString()).toBe('content foo');
const fromStream = await buffer();
const res = await fromStream;
expect(res.toString()).toBe('content foo');
});
it('should throw NotFound if server responds with 404', async () => {
@@ -26,7 +26,6 @@ import { getVoidLogger } from '../logging';
import { GitlabUrlReader } from './GitlabUrlReader';
import { DefaultReadTreeResponseFactory } from './tree';
import { NotModifiedError, NotFoundError } from '@backstage/errors';
import getRawBody from 'raw-body';
import {
GitLabIntegration,
readGitLabIntegrationConfig,
@@ -151,8 +150,8 @@ describe('GitlabUrlReader', () => {
treeResponseFactory,
});
const data = await reader.readUrl(url);
const fromStream = await getRawBody(data.stream!());
const { buffer } = await reader.readUrl(url);
const fromStream = await buffer();
const res = await JSON.parse(fromStream.toString());
expect(res).toEqual(response);
});
@@ -1,172 +0,0 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ConfigReader } from '@backstage/config';
import { isError } from '@backstage/errors';
import { getVoidLogger } from '../logging';
import { UrlReaders } from './UrlReaders';
const reader = UrlReaders.default({
logger: getVoidLogger(),
config: new ConfigReader({
// The tokens in this config provide read only access to the backstage-verification repos
integrations: {
github: [
{
host: 'github.com',
token:
process.env.INTEGRATION_TEST_GITHUB_TOKEN ||
`${86}af${617}d9c3c8bf958b37a${630691452765}bb0b0a`,
},
],
gitlab: [
{
host: 'gitlab.com',
token:
process.env.INTEGRATION_TEST_GITLAB_TOKEN || 'tveGtSHDBJM9ZRHZNRfm',
},
],
bitbucket: [
{
host: 'bitbucket.org',
username: 'backstage-verification',
appPassword:
process.env.INTEGRATION_TEST_BITBUCKET_TOKEN ||
'H79MAAhtbZwCafkVTrrQ',
},
],
azure: [
{
host: 'dev.azure.com',
// lasts until 2022-01-28
token:
process.env.INTEGRATION_TEST_AZURE_TOKEN ||
`myvyavvfojh6wvw4ose4bfywqttqx${5}z${5}zs${5}bdxauqaek3yinkazq`,
},
],
},
}),
});
function withRetries(count: number, fn: () => Promise<void>) {
return async () => {
let error;
for (let i = 0; i < count; i++) {
try {
await fn();
return;
} catch (err) {
error = err;
}
}
if (
isError(error) &&
!error.message.match(/rate limit|Too Many Requests/)
) {
throw error;
} else {
console.warn('Request was rate limited', error);
}
};
}
/* eslint-disable jest/no-disabled-tests */
describe.skip('UrlReaders', () => {
jest.setTimeout(30_000);
it(
'should read data from azure',
withRetries(3, async () => {
const data = await reader.readUrl(
'https://dev.azure.com/backstage-verification/test-templates/_git/test-templates?path=%2Ftemplate.yaml',
);
expect(data.toString()).toContain('test-template-azure');
const res = await reader.readTree(
'https://dev.azure.com/backstage-verification/test-templates/_git/test-templates?path=%2F{{cookiecutter.name}}',
);
const files = await res.files();
expect(files).toEqual([
{
path: 'catalog-info.yaml',
content: expect.any(Function),
},
]);
}),
);
it(
'should read data from gitlab',
withRetries(3, async () => {
const data = await reader.readUrl(
'https://gitlab.com/backstage-verification/test-templates/-/blob/master/template.yaml',
);
expect(data.toString()).toContain('test-template-gitlab');
const res = await reader.readTree(
'https://gitlab.com/backstage-verification/test-templates/-/tree/master/{{cookiecutter.name}}',
);
const files = await res.files();
expect(files).toEqual([
{
path: 'catalog-info.yaml',
content: expect.any(Function),
},
]);
}),
);
it(
'should read data from bitbucket',
withRetries(3, async () => {
const data = await reader.readUrl(
'https://bitbucket.org/backstage-verification/test-template/src/master/template.yaml',
);
expect(data.toString()).toContain('test-template-bitbucket');
const res = await reader.readTree(
'https://bitbucket.org/backstage-verification/test-template/src/master/{{cookiecutter.name}}',
);
const files = await res.files();
expect(files).toEqual([
{
path: 'catalog-info.yaml',
content: expect.any(Function),
},
]);
}),
);
it(
'should read data from github',
withRetries(3, async () => {
const data = await reader.readUrl(
'https://github.com/backstage-verification/test-templates/blob/master/template.yaml',
);
expect(data.toString()).toContain('test-template-github');
const res = await reader.readTree(
'https://github.com/backstage-verification/test-templates/tree/master/{{cookiecutter.name}}',
);
const files = await res.files();
expect(files).toEqual([
{
path: 'catalog-info.yaml',
content: expect.any(Function),
},
]);
}),
);
});
+1 -1
View File
@@ -25,6 +25,6 @@ export type {
JsonObject,
JsonPrimitive,
JsonValue,
} from '@backstage/types';
} from './deprecatedTypes';
export { ConfigReader } from './reader';
export type { AppConfig, Config } from './types';