Skip to content

Commit 2e0606f

Browse files
committed
moved clearBucket call in deleteBucket to abstract adapter, reorganize tests
1 parent b13d346 commit 2e0606f

File tree

11 files changed

+27
-75
lines changed

11 files changed

+27
-75
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: ci
33
on:
44
push:
55
branches:
6-
- master
6+
- dev
77
pull_request:
88
branches:
99
- "*"
@@ -30,4 +30,4 @@ jobs:
3030
node-modules-cache-${{matrix.node-version}}-${{runner.os}}-
3131
- run: npm ci
3232
- run: npm run test-local
33-
# - run: npm run test-minio-2
33+
- run: npm run test-minio

package.json

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,11 @@
3838
"typescript": "^5.9.3"
3939
},
4040
"scripts": {
41-
"test-all": "npm run test-jasmine local && npm run test-gcs && npm run test-s3 && npm run test-b2 && npm run test-azure && npm run test-minio && npm run test-minio-s3 && npm run test-cubbit && npm run test-cloudflare && npm run test-b2-s3",
41+
"test-all": "npm run test-local && npm run test-jasmine gcs && npm run test-jasmine s3 && npm run test-jasmine b2 && npm run test-jasmine azure && npm run test-jasmine minio && npm run test-jasmine minio-s3 && npm run test-jasmine cubbit && npm run test-jasmine cloudflare && npm run test-jasmine b2-s3",
4242
"test-jasmine": "node ./node_modules/.bin/jasmine --random=false --fail-fast ./publish/dist/tests/test.jasmine.js",
43-
"test-jasmine-1": "ts-node -O '{\"module\":\"commonjs\"}' ./node_modules/.bin/jasmine --random=false --fail-fast ./tests/test.jasmine.ts",
43+
"test-jasmine-1": "ts-node ./node_modules/.bin/jasmine --random=false --fail-fast ./tests/test.jasmine.ts",
4444
"test-local": "LOCAL_DIRECTORY='tests/test_directory' npm run test-jasmine local",
45-
"test-s3": "npm run test-jasmine s3",
46-
"test-gcs": "npm run test-jasmine gcs",
47-
"test-b2": "npm run test-jasmine b2",
48-
"test-b2-s3": "npm run test-jasmine b2-s3",
49-
"test-azure": "npm run test-jasmine azure",
50-
"test-minio": "npm run test-jasmine minio",
51-
"test-minio-s3": "npm run test-jasmine minio-s3",
52-
"test-cubbit": "npm run test-jasmine cubbit",
53-
"test-cloudflare": "npm run test-jasmine r2",
54-
"test-minio-2": "MINIO_ENDPOINT='play.min.io' MINIO_USE_SSL='true' MINIO_PORT='9000' MINIO_REGION='us-east-1' MINIO_ACCESS_KEY='Q3AM3UQ867SPQQA43P2F' MINIO_SECRET_KEY='zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG' npm run test-jasmine minio",
45+
"test-minio": "MINIO_ENDPOINT='play.min.io' MINIO_USE_SSL='true' MINIO_PORT='9000' MINIO_REGION='us-east-1' MINIO_ACCESS_KEY='Q3AM3UQ867SPQQA43P2F' MINIO_SECRET_KEY='zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG' npm run test-jasmine minio",
5546
"test": "ts-node ./tests/test_runs.ts",
5647
"test2": "ts-node ./tests/test2.ts",
5748
"toc": "ts-node ./toc/replace.ts && cd ./toc && ./create_toc.sh && cd ../",

src/AbstractAdapter.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,19 @@ export abstract class AbstractAdapter implements IAdapter {
298298
}
299299
}
300300
name = r.value as string;
301-
if (this.selectedBucket === name) {
302-
this.selectedBucket = null;
301+
302+
const data = await this._clearBucket(name);
303+
if (data.error !== null) {
304+
return { value: null, error: data.error };
305+
}
306+
307+
const r2 = await this._deleteBucket(name);
308+
if (r2.error === null) {
309+
if (this.selectedBucket === name) {
310+
this.selectedBucket = null;
311+
}
303312
}
304-
return this._deleteBucket(name);
313+
return r2;
305314
}
306315

307316
public async bucketExists(name?: string): Promise<ResultObjectBoolean> {
@@ -371,8 +380,7 @@ export abstract class AbstractAdapter implements IAdapter {
371380
return { value: null, error: error as string };
372381
}
373382

374-
console.log(bucketName, _fn, options, error);
375-
383+
// console.log(bucketName, _fn, options, error);
376384

377385
const r = await this.checkBucket(bucketName);
378386
if (r.error !== null) {

src/AdapterAmazonS3.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,6 @@ export class AdapterAmazonS3 extends AbstractAdapter {
369369

370370
protected async _deleteBucket(bucketName: string): Promise<ResultObject> {
371371
try {
372-
const r = await this._clearBucket(bucketName);
373-
if (r.error !== null) {
374-
return { value: null, error: r.error };
375-
}
376372
const input = {
377373
Bucket: bucketName,
378374
};

src/AdapterAzureBlob.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ export class AdapterAzureBlob extends AbstractAdapter {
280280

281281
protected async _deleteBucket(name: string): Promise<ResultObject> {
282282
try {
283-
await this.clearBucket(name);
284283
const del = await this._client.deleteContainer(name);
285284
//console.log('deleting container: ', del);
286285
return { value: "ok", error: null };

src/AdapterBackblazeB2.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,6 @@ export class AdapterBackblazeB2 extends AbstractAdapter {
473473
}
474474

475475
protected async _deleteBucket(name: string): Promise<ResultObject> {
476-
const data = await this.clearBucket(name);
477-
if (data.error !== null) {
478-
return { value: null, error: data.error };
479-
}
480-
481476
const { error, value: bucket } = await this.getBucket(name);
482477
if (bucket === null) {
483478
return { value: null, error: error };

src/AdapterGoogleCloud.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,6 @@ export class AdapterGoogleCloud extends AbstractAdapter {
275275
}
276276

277277
protected async _deleteBucket(name: string): Promise<ResultObject> {
278-
try {
279-
await this.clearBucket(name);
280-
} catch (e) {
281-
return { value: null, error: getErrorMessage(e) };
282-
}
283278
try {
284279
await this._client.bucket(name).delete();
285280
return { value: "ok", error: null };

src/AdapterMinio.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ export class AdapterMinio extends AbstractAdapter {
203203

204204
protected async _deleteBucket(name: string): Promise<ResultObject> {
205205
try {
206-
await this.clearBucket(name);
207206
await this._client.removeBucket(name);
208207
return { value: "ok", error: null };
209208
} catch (e) {

tests/api_calls.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { fileTypeFromBuffer } from 'file-type';
66
import { Storage } from "../src/Storage";
77
import { IAdapter, Options, Provider } from "../src/types/general";
88
import { getConfig } from "./config";
9-
import { Color, colorLog, logResult, saveFile, getSha1ForFile, getPrivateBucketName } from "./util";
9+
import { Color, colorLog, logResult, saveFile, getSha1ForFile, getPrivateBucketName, timeout } from "./util";
1010
import { ResultObject } from "../src/types/result";
1111
import dotenv from "dotenv";
1212

@@ -97,7 +97,7 @@ export async function init(_provider: Provider, bucketName?: string): Promise<st
9797
export async function deleteAllBuckets(
9898
list: Array<string>,
9999
storage: IAdapter,
100-
delay: number = 500
100+
delay?: number
101101
): Promise<ResultObject> {
102102
colorLog("init::deleteAllBuckets", Color.MESSAGE, list);
103103
for (let i = 0; i < list.length; i++) {
@@ -126,6 +126,9 @@ export async function deleteAllBuckets(
126126
return { value: null, error: r.error };
127127
}
128128
}
129+
if (typeof delay === "number") {
130+
await timeout(delay);
131+
}
129132
}
130133
return { value: "ok", error: null };
131134
}

tests/test.jasmine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let provider = Provider.LOCAL;
2020
if (process.argv[5]) {
2121
provider = process.argv[5] as Provider;
2222
}
23-
console.log(provider);
23+
// console.log(provider);
2424
const config: StorageAdapterConfig | string = getConfig(provider);
2525

2626
const newBucketName1 = "bucket-test-sab-1";

0 commit comments

Comments
 (0)