Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit a10b91e

Browse files
authored
test: Clean-up sample test buckets by prefix (#1825)
* test: Clean-up sample test buckets by prefix * fix: cap bucket name to 63 characters https://cloud.google.com/storage/docs/naming-buckets#requirements
1 parent cf6f787 commit a10b91e

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

samples/system-test/buckets.test.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ const uuid = require('uuid');
2323
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2424

2525
const storage = new Storage();
26-
const bucketName = `nodejs-storage-samples-${uuid.v4()}`;
27-
const bucketNameDualRegion = `nodejs-storage-samples-${uuid.v4()}`;
28-
const bucketNameWithClassAndLocation = `nodejs-storage-samples-${uuid.v4()}`;
26+
const samplesTestBucketPrefix = `nodejs-storage-samples-${uuid.v4()}`;
27+
const bucketName = `${samplesTestBucketPrefix}-a`;
28+
const bucketNameDualRegion = `${samplesTestBucketPrefix}-b`;
29+
const bucketNameWithClassAndLocation = `${samplesTestBucketPrefix}-c`;
2930
const defaultKmsKeyName = process.env.GOOGLE_CLOUD_KMS_KEY_ASIA;
3031
const bucket = storage.bucket(bucketName);
3132
const bucketWithClassAndLocation = storage.bucket(
@@ -39,10 +40,16 @@ const PUBLIC_ACCESS_PREVENTION_ENFORCED = 'enforced';
3940
const RPO_ASYNC_TURBO = 'ASYNC_TURBO';
4041
const RPO_DEFAULT = 'DEFAULT';
4142

42-
after(async () => {
43-
await bucket.delete().catch(console.error);
44-
await bucketWithClassAndLocation.delete().catch(console.error);
45-
});
43+
async function deleteAllBucketsAsync() {
44+
const [buckets] = await storage.getBuckets({prefix: samplesTestBucketPrefix});
45+
46+
for (const bucket of buckets) {
47+
await bucket.deleteFiles({force: true});
48+
await bucket.delete({ignoreNotFound: true});
49+
}
50+
}
51+
52+
after(deleteAllBucketsAsync);
4653

4754
it('should create a bucket', async () => {
4855
const output = execSync(`node createNewBucket.js ${bucketName}`);

0 commit comments

Comments
 (0)