Skip to content

Commit

Permalink
feat: add support for matchGlob list option (#2206)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelgrosso1 authored Jun 2, 2023
1 parent 8c6f9c6 commit 79dd839
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export interface GetFilesOptions {
endOffset?: string;
includeTrailingDelimiter?: boolean;
prefix?: string;
matchGlob?: string;
maxApiCalls?: number;
maxResults?: number;
pageToken?: string;
Expand Down Expand Up @@ -2528,6 +2529,8 @@ class Bucket extends ServiceObject {
* in addition to the relevant part of the object name appearing in prefixes[].
* @property {string} [prefix] Filter results to objects whose names begin
* with this prefix.
* @property {string} [matchGlob] A glob pattern used to filter results,
* for example foo*bar
* @property {number} [maxApiCalls] Maximum number of API calls to make.
* @property {number} [maxResults] Maximum number of items plus prefixes to
* return per call.
Expand Down
22 changes: 22 additions & 0 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,28 @@ describe('storage', () => {
});
});

it('should only get files matching the supplied matchGlob argument', async () => {
let expectedFileNames = ['CloudLogo1', 'CloudLogo2', 'CloudLogo3'];
let [files] = await bucket.getFiles({matchGlob: 'CloudLogo*'});
assert.strictEqual(files.length, expectedFileNames.length);
for (const curFile of files) {
assert.strictEqual(expectedFileNames.includes(curFile.name), true);
}

expectedFileNames = [
`${DIRECTORY_NAME}/CloudLogo4`,
`${DIRECTORY_NAME}/CloudLogo5`,
`${DIRECTORY_NAME}/inner/CloudLogo6`,
];
[files] = await bucket.getFiles({
matchGlob: `${DIRECTORY_NAME}/**/CloudLogo*`,
});
assert.strictEqual(files.length, expectedFileNames.length);
for (const curFile of files) {
assert.strictEqual(expectedFileNames.includes(curFile.name), true);
}
});

it('should paginate the list', async () => {
const query = {
maxResults: NEW_FILES.length - 1,
Expand Down

0 comments on commit 79dd839

Please sign in to comment.