Skip to content

Commit

Permalink
fix: use correct indices for file.from and fix tests to verify names (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelgrosso1 authored Apr 26, 2024
1 parent 2eacda8 commit d4240fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
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');
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

0 comments on commit d4240fa

Please sign in to comment.