diff --git a/packages/backend-common/src/reading/AwsS3UrlReader.test.ts b/packages/backend-common/src/reading/AwsS3UrlReader.test.ts index 78bfdbb0e2..78cdcbb7b9 100644 --- a/packages/backend-common/src/reading/AwsS3UrlReader.test.ts +++ b/packages/backend-common/src/reading/AwsS3UrlReader.test.ts @@ -139,6 +139,7 @@ describe('AwsS3UrlReader', () => { 'src', 'reading', '__fixtures__', + 'awsS3', 'awsS3-mock-object.yaml', ), ), @@ -191,6 +192,7 @@ describe('AwsS3UrlReader', () => { 'src', 'reading', '__fixtures__', + 'awsS3', 'awsS3-mock-object.yaml', ), ), diff --git a/packages/backend-common/src/reading/__fixtures__/awsS3-mock-object.yaml b/packages/backend-common/src/reading/__fixtures__/awsS3/awsS3-mock-object.yaml similarity index 100% rename from packages/backend-common/src/reading/__fixtures__/awsS3-mock-object.yaml rename to packages/backend-common/src/reading/__fixtures__/awsS3/awsS3-mock-object.yaml diff --git a/packages/backend-common/src/reading/__fixtures__/awsS3/awsS3-mock-object2.yaml b/packages/backend-common/src/reading/__fixtures__/awsS3/awsS3-mock-object2.yaml new file mode 100644 index 0000000000..b2c132961b --- /dev/null +++ b/packages/backend-common/src/reading/__fixtures__/awsS3/awsS3-mock-object2.yaml @@ -0,0 +1 @@ +site_name: Test2 diff --git a/packages/backend-common/src/reading/tree/ReadableArrayResponse.test.ts b/packages/backend-common/src/reading/tree/ReadableArrayResponse.test.ts new file mode 100644 index 0000000000..c2e3c26269 --- /dev/null +++ b/packages/backend-common/src/reading/tree/ReadableArrayResponse.test.ts @@ -0,0 +1,62 @@ +/* + * Copyright 2021 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 { ReadableArrayResponse } from './ReadableArrayResponse'; +import path from 'path'; +import { Readable } from 'stream'; +import fs from 'fs'; + +const arr: Readable[] = []; +const file1 = path.resolve( + 'src', + 'reading', + '__fixtures__', + 'awsS3', + 'awsS3-mock-object.yaml', +); +const file2 = path.resolve( + 'src', + 'reading', + '__fixtures__', + 'awsS3', + 'awsS3-mock-object2.yaml', +); +const stream1 = fs.createReadStream(file1); +const stream2 = fs.createReadStream(file2); +arr.push(stream1); +arr.push(stream2); + +describe('ReadableArrayResponse', () => { + it('should read files', async () => { + const res = new ReadableArrayResponse(arr, 'etag'); + const files = await res.files(); + + expect(files).toEqual([ + { + path: file1, + content: expect.any(Function), + }, + { + path: file2, + content: expect.any(Function), + }, + ]); + const contents = await Promise.all(files.map(f => f.content())); + expect(contents.map(c => c.toString('utf8').trim())).toEqual([ + 'site_name: Test', + 'site_name: Test2', + ]); + }); +});