Skip to content

Commit

Permalink
fix: don't modify passed in options (#1895)
Browse files Browse the repository at this point in the history
* fix: don't modify passed in options

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* added test

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
shaffeeullah and gcf-owl-bot[bot] authored Apr 28, 2022
1 parent 3d86c7c commit cd80ca3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ class File extends ServiceObject<File> {
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
createWriteStream(options: CreateWriteStreamOptions = {}): Writable {
options = Object.assign({metadata: {}}, options);
options = extend(true, {metadata: {}}, options);

if (options.contentType) {
options.metadata.contentType = options.contentType;
Expand Down Expand Up @@ -3951,7 +3951,8 @@ class File extends ServiceObject<File> {
dup: Duplexify,
options: CreateResumableUploadOptions
): void {
options = Object.assign(
options = extend(
true,
{
metadata: {},
},
Expand Down Expand Up @@ -4019,7 +4020,8 @@ class File extends ServiceObject<File> {
* @private
*/
startSimpleUpload_(dup: Duplexify, options?: CreateWriteStreamOptions): void {
options = Object.assign(
options = extend(
true,
{
metadata: {},
},
Expand Down
22 changes: 15 additions & 7 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,6 @@ describe('File', () => {
const writable = file.createWriteStream(options);

file.startSimpleUpload_ = (stream: {}, options_: {}) => {
assert.deepStrictEqual(options_, options);
done();
};

Expand All @@ -2034,7 +2033,6 @@ describe('File', () => {
const writable = file.createWriteStream(options);

file.startResumableUpload_ = (stream: {}, options_: {}) => {
assert.deepStrictEqual(options_, options);
done();
};

Expand All @@ -2050,7 +2048,6 @@ describe('File', () => {
const writable = file.createWriteStream(options);

file.startResumableUpload_ = (stream: {}, options_: {}) => {
assert.deepStrictEqual(options_, options);
done();
};

Expand Down Expand Up @@ -2170,7 +2167,6 @@ describe('File', () => {
});

file.startSimpleUpload_ = (stream: Stream, _options: {}) => {
assert.deepStrictEqual(_options, options);
done();
};

Expand All @@ -2185,7 +2181,6 @@ describe('File', () => {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
file.startResumableUpload_ = (stream: {}, options: any) => {
assert.deepStrictEqual(options.metadata, METADATA);
done();
};

Expand Down Expand Up @@ -2226,6 +2221,19 @@ describe('File', () => {
writable.write('data');
});

it('should not overwrite passed in options', done => {
const emptyObject = {};
const writable = file.createWriteStream(emptyObject);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
file.startResumableUpload_ = (stream: {}, options: any) => {
assert.strictEqual(options.metadata.contentType, 'image/png');
assert.deepStrictEqual(emptyObject, {});
done();
};

writable.write('data');
});

it('should not set a contentType if mime lookup failed', done => {
const file = new File('file-without-ext');
const writable = file.createWriteStream();
Expand Down Expand Up @@ -4829,7 +4837,7 @@ describe('File', () => {
assert.strictEqual(opts.file, file.name);
assert.strictEqual(opts.generation, file.generation);
assert.strictEqual(opts.key, file.encryptionKey);
assert.strictEqual(opts.metadata, options.metadata);
assert.deepStrictEqual(opts.metadata, options.metadata);
assert.strictEqual(opts.offset, options.offset);
assert.strictEqual(opts.predefinedAcl, options.predefinedAcl);
assert.strictEqual(opts.private, options.private);
Expand Down Expand Up @@ -4992,7 +5000,7 @@ describe('File', () => {

// eslint-disable-next-line @typescript-eslint/no-explicit-any
makeWritableStreamOverride = (stream: {}, options_: any) => {
assert.strictEqual(options_.metadata, options.metadata);
assert.deepStrictEqual(options_.metadata, options.metadata);
assert.deepStrictEqual(options_.request, {
qs: {
name: file.name,
Expand Down

0 comments on commit cd80ca3

Please sign in to comment.