Skip to content

Commit

Permalink
fix tests to be more robust with path separators
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelgrosso1 committed Oct 5, 2023
1 parent 7c63d0b commit c0793bc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions test/transfer-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,29 +113,38 @@ describe('Transfer Manager', () => {
});

it('sets destination to prefix + filename when prefix is supplied', async () => {
const paths = ['/a/b/foo/bar.txt'];
const expectedDestination = path.normalize('hello/world/a/b/foo/bar.txt');
const filePaths = ['a', 'b', 'foo', 'bar.txt'].join(path.sep);
const expectedDestination = [
'hello',
'world',
'a',
'b',
'foo',
'bar.txt',
].join(path.posix.sep);
sandbox.stub(bucket, 'upload').callsFake((path, options) => {
assert.strictEqual(
(options as UploadOptions).destination,
expectedDestination
);
});

await transferManager.uploadManyFiles(paths, {prefix: 'hello/world'});
await transferManager.uploadManyFiles([filePaths], {
prefix: ['hello', 'world'].join(path.sep),
});
});

it('returns a promise with the uploaded file if there is no callback', async () => {
const paths = [path.join(__dirname, '../../test/testdata/testfile.json')];
const paths = [['a', 'b', 'foo', 'bar.txt'].join(path.sep)];
sandbox.stub(bucket, 'upload').callsFake(() => {
const resp = [{name: paths[0]}];
const resp = [{name: paths[0].split(path.sep).join(path.posix.sep)}];
return Promise.resolve(resp);
});

const result = await transferManager.uploadManyFiles(paths);
assert.strictEqual(
result[0][0].name,
paths[0].split(path.win32.sep).join(path.posix.sep)
paths[0].split(path.sep).join(path.posix.sep)
);
});

Expand Down

0 comments on commit c0793bc

Please sign in to comment.