Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use correct indices for file.from and fix tests to verify names #2449

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2410,11 +2410,11 @@ class File extends ServiceObject<File, FileMetadata> {
const httpsMatches = [...publicUrlOrGsUrl.matchAll(HTTPS_PUBLIC_URL_REGEX)];

if (gsMatches.length > 0) {
const bucket = new Bucket(storageInstance, gsMatches[0][1]);
return new File(bucket, gsMatches[0][2], options);
const bucket = new Bucket(storageInstance, gsMatches[0][2]);
return new File(bucket, gsMatches[0][3], options);
} else if (httpsMatches.length > 0) {
const bucket = new Bucket(storageInstance, httpsMatches[0][2]);
return new File(bucket, httpsMatches[0][3], options);
const bucket = new Bucket(storageInstance, httpsMatches[0][3]);
return new File(bucket, httpsMatches[0][4], options);
} else {
throw new Error(
'URL string must be of format gs://bucket/file or https://storage.googleapis.com/bucket/file'
Expand Down
16 changes: 8 additions & 8 deletions test/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5180,26 +5180,26 @@ describe('File', () => {
const result = File.from(gsUrl, STORAGE);

assert(result);
assert(result.bucket.name, 'mybucket');
assert(result.name, 'myfile');
assert.strictEqual(result.bucket.name, 'mybucket');
assert.strictEqual(result.name, 'myfile');
});

it('should create a File object from a gs:// formatted URL including a folder', () => {
const gsUrl = 'gs://mybucket/myfolder/myfile';
const result = File.from(gsUrl, STORAGE);

assert(result);
assert(result.bucket.name, 'mybucket');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, the assert with 2 params gets me too at times.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where the ‘mybucket’ here is treated as the error message

assert(result.name, 'myfolder/myfile');
assert.strictEqual(result.bucket.name, 'mybucket');
assert.strictEqual(result.name, 'myfolder/myfile');
});

it('should create a File object from a https:// formatted URL', () => {
const httpsUrl = 'https://storage.googleapis.com/mybucket/myfile';
const result = File.from(httpsUrl, STORAGE);

assert(result);
assert(result.bucket.name, 'mybucket');
assert(result.name, 'myfile');
assert.strictEqual(result.bucket.name, 'mybucket');
assert.strictEqual(result.name, 'myfile');
});

it('should create a File object from a https:// formatted URL including a folder', () => {
Expand All @@ -5208,8 +5208,8 @@ describe('File', () => {
const result = File.from(httpsUrl, STORAGE);

assert(result);
assert(result.bucket.name, 'mybucket');
assert(result.name, 'myfolder/myfile');
assert.strictEqual(result.bucket.name, 'mybucket');
assert.strictEqual(result.name, 'myfolder/myfile');
});

it('should throw an error when invoked with an incorrectly formatted URL', () => {
Expand Down