Skip to content

Commit

Permalink
fix: update CopyOptions type to include cacheControl, contentType and…
Browse files Browse the repository at this point in the history
… contentEncoding (#1426)

* updated file copy options to provide documentation for existing functionality

* updated system test to confirm existing functionality

* updated content type
  • Loading branch information
shaffeeullah committed Mar 23, 2021
1 parent 1f63a82 commit efa5bb8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ export interface FileOptions {
}

export interface CopyOptions {
cacheControl?: string;
contentEncoding?: string;
contentType?: string;
destinationKmsKeyName?: string;
metadata?: Metadata;
predefinedAcl?: string;
Expand Down Expand Up @@ -857,6 +860,9 @@ class File extends ServiceObject<File> {
* @typedef {object} CopyOptions Configuration options for File#copy(). See an
* [Object
* resource](https://cloud.google.com/storage/docs/json_api/v1/objects#resource).
* @property {string} [cacheControl] The cacheControl setting for the new file.
* @property {string} [contentEncoding] The contentEncoding setting for the new file.
* @property {string} [contentType] The contentType setting for the new file.
* @property {string} [destinationKmsKeyName] Resource name of the Cloud
* KMS key, of the form
* `projects/my-project/locations/location/keyRings/my-kr/cryptoKeys/my-key`,
Expand Down
23 changes: 22 additions & 1 deletion system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,7 @@ describe('storage', () => {
await Promise.all([file.delete, copiedFile.delete()]);
});

it('should copy an existing file and overwrite metadata', async () => {
it('should copy an existing file and overwrite custom metadata', async () => {
const opts = {
destination: 'CloudLogo',
metadata: {
Expand All @@ -2831,6 +2831,27 @@ describe('storage', () => {
await Promise.all([file.delete, copiedFile.delete()]);
});

it('should copy an existing file and overwrite metadata', async () => {
const opts = {
destination: 'CloudLogo',
};
const CACHE_CONTROL = 'private';
const CONTENT_ENCODING = 'gzip';
const CONTENT_TYPE = 'text/plain';
const [file] = await bucket.upload(FILES.logo.path, opts);
const copyOpts = {
cacheControl: CACHE_CONTROL,
contentEncoding: CONTENT_ENCODING,
contentType: CONTENT_TYPE,
};
const [copiedFile] = await file.copy('CloudLogoCopy', copyOpts);
const [metadata] = await copiedFile.getMetadata();
assert.strictEqual(metadata.contentEncoding, CONTENT_ENCODING);
assert.strictEqual(metadata.cacheControl, CACHE_CONTROL);
assert.strictEqual(metadata.contentType, CONTENT_TYPE);
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 efa5bb8

Please sign in to comment.