update tests to include subdirectory validation

Signed-off-by: Matt Wise <wsmatth@amazon.com>
This commit is contained in:
Matt Wise
2024-02-13 09:12:48 -06:00
parent 04547bc042
commit c71e8770e2
2 changed files with 19 additions and 1 deletions
@@ -0,0 +1 @@
site_name: Test3
@@ -31,6 +31,12 @@ const file2 = fs.readFileSync(
path.resolve(__filename, '../../__fixtures__/awsS3/awsS3-mock-object2.yaml'),
);
const dir1 = 'dir1';
const name3 = `file3.yaml`;
const file3 = fs.readFileSync(
path.resolve(__filename, '../../__fixtures__/awsS3/awsS3-mock-object3.yaml'),
);
describe('ReadableArrayResponse', () => {
const sourceDir = createMockDirectory();
const targetDir = createMockDirectory();
@@ -39,6 +45,9 @@ describe('ReadableArrayResponse', () => {
sourceDir.setContent({
[name1]: file1,
[name2]: file2,
[dir1]: {
[name3]: file3,
},
});
targetDir.clear();
});
@@ -56,11 +65,13 @@ describe('ReadableArrayResponse', () => {
const path1 = sourceDir.resolve(name1);
const path2 = sourceDir.resolve(name2);
const path3 = sourceDir.resolve(`${dir1}/${name3}`);
it('should read files', async () => {
const arr: FromReadableArrayOptions = [
{ data: createReadStream(path1), path: path1 },
{ data: createReadStream(path2), path: path2 },
{ data: createReadStream(path3), path: path3 },
];
const res = new ReadableArrayResponse(arr, targetDir.path, 'etag');
@@ -69,18 +80,21 @@ describe('ReadableArrayResponse', () => {
expect(files).toEqual([
{ path: path1, content: expect.any(Function) },
{ path: path2, content: expect.any(Function) },
{ path: path3, content: expect.any(Function) },
]);
const contents = await Promise.all(files.map(f => f.content()));
expect(contents).toEqual([file1, file2]);
expect(contents).toEqual([file1, file2, file3]);
});
it('should extract entire archive into directory', async () => {
const relativePath1 = relative(sourceDir.path, path1);
const relativePath2 = relative(sourceDir.path, path2);
const relativePath3 = relative(sourceDir.path, path3);
const arr: FromReadableArrayOptions = [
{ data: createReadStream(path1), path: relativePath1 },
{ data: createReadStream(path2), path: relativePath2 },
{ data: createReadStream(path3), path: relativePath3 },
];
const res = new ReadableArrayResponse(arr, targetDir.path, 'etag');
@@ -89,6 +103,9 @@ describe('ReadableArrayResponse', () => {
expect(targetDir.content({ path: dir })).toEqual({
[name1]: file1.toString('utf8'),
[name2]: file2.toString('utf8'),
[dir1]: {
[name3]: file3.toString('utf8'),
},
});
});
});