Skip to content

Commit

Permalink
feat: support OLM Prefix/Suffix (#1847)
Browse files Browse the repository at this point in the history
* feat: support OLM Prefix/Suffix

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* updated to camel case

* fix merge

* fixed compile error

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* refactored tests

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* refactored tests

* refactored tests

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
shaffeeullah and gcf-owl-bot[bot] committed Jun 8, 2022
1 parent 594e7da commit c22984c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export interface AddLifecycleRuleOptions {

export interface LifecycleRule {
action: {type: string; storageClass?: string} | string;
condition: {[key: string]: boolean | Date | number | string};
condition: {[key: string]: boolean | Date | number | string | string[]};
storageClass?: string;
}

Expand Down
38 changes: 38 additions & 0 deletions system-test/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,44 @@ describe('storage', () => {
);
});

it('should add a prefix rule', async () => {
await bucket.addLifecycleRule({
action: 'delete',
condition: {
matchesPrefix: [TESTS_PREFIX],
},
});

assert(
bucket.metadata.lifecycle.rule.some(
(rule: LifecycleRule) =>
typeof rule.action === 'object' &&
rule.action.type === 'Delete' &&
typeof rule.condition.matchesPrefix === 'object' &&
(rule.condition.matchesPrefix as string[]).length === 1 &&
Array.isArray(rule.condition.matchesPrefix)
)
);
});

it('should add a suffix rule', async () => {
await bucket.addLifecycleRule({
action: 'delete',
condition: {
matchesSuffix: [TESTS_PREFIX, 'test_suffix'],
},
});

assert(
bucket.metadata.lifecycle.rule.some(
(rule: LifecycleRule) =>
typeof rule.action === 'object' &&
rule.action.type === 'Delete' &&
Array.isArray(rule.condition.matchesPrefix)
)
);
});

it('should convert a rule with createdBefore to a date in string', done => {
bucket.addLifecycleRule(
{
Expand Down

0 comments on commit c22984c

Please sign in to comment.