Skip to content

Commit

Permalink
fix(types): support metadata override in file.copy() (#1406)
Browse files Browse the repository at this point in the history
* fix(types): support metadata override in file.copy()

* lint

Co-authored-by: Sameena Shaffeeullah <shaffeeullah@google.com>
  • Loading branch information
stephenplusplus and shaffeeullah authored Feb 26, 2021
1 parent 65f3ee5 commit dda6d30
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export interface FileOptions {

export interface CopyOptions {
destinationKmsKeyName?: string;
metadata?: Metadata;
predefinedAcl?: string;
token?: string;
userProject?: string;
Expand Down Expand Up @@ -861,6 +862,7 @@ class File extends ServiceObject<File> {
* `projects/my-project/locations/location/keyRings/my-kr/cryptoKeys/my-key`,
* that will be used to encrypt the object. Overwrites the object
* metadata's `kms_key_name` value, if any.
* @property {Metadata} [metadata] Metadata to specify on the copied file.
* @property {string} [predefinedAcl] Set the ACL for the new file.
* @property {string} [token] A previously-returned `rewriteToken` from an
* unfinished rewrite request.
Expand Down
21 changes: 21 additions & 0 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2810,6 +2810,27 @@ describe('storage', () => {
await Promise.all([file.delete, copiedFile.delete()]);
});

it('should copy an existing file and overwrite metadata', async () => {
const opts = {
destination: 'CloudLogo',
metadata: {
metadata: {
originalProperty: 'true',
},
},
};
const [file] = await bucket.upload(FILES.logo.path, opts);
const copyOpts = {metadata: {newProperty: 'true'}};
const [copiedFile] = await file.copy('CloudLogoCopy', copyOpts);
const [metadata] = await copiedFile.getMetadata();
assert.strictEqual(
typeof metadata.metadata.originalProperty,
'undefined'
);
assert.strictEqual(metadata.metadata.newProperty, 'true');
await Promise.all([file.delete, copiedFile.delete()]);
});

it('should respect predefined Acl at file#copy', async () => {
const opts = {destination: 'CloudLogo'};
const [file] = await bucket.upload(FILES.logo.path, opts);
Expand Down

0 comments on commit dda6d30

Please sign in to comment.