fix(core): update
This commit is contained in:
parent
c333533c63
commit
caf0566020
13
test/test.ts
13
test/test.ts
@ -6,6 +6,7 @@ import * as smartbucket from '../ts/index';
|
|||||||
const testQenv = new Qenv('./', './.nogit/');
|
const testQenv = new Qenv('./', './.nogit/');
|
||||||
|
|
||||||
let testSmartbucket: smartbucket.SmartBucket;
|
let testSmartbucket: smartbucket.SmartBucket;
|
||||||
|
let myBucket: smartbucket.Bucket;
|
||||||
|
|
||||||
tap.test('should create a valid smartbucket', async () => {
|
tap.test('should create a valid smartbucket', async () => {
|
||||||
testSmartbucket = new smartbucket.SmartBucket({
|
testSmartbucket = new smartbucket.SmartBucket({
|
||||||
@ -15,7 +16,7 @@ tap.test('should create a valid smartbucket', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.skip.test('should create a bucket', async () => {
|
tap.skip.test('should create testbucket', async () => {
|
||||||
await testSmartbucket.createBucket('smartbucket');
|
await testSmartbucket.createBucket('smartbucket');
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -23,4 +24,14 @@ tap.skip.test('should remove testbucket', async () => {
|
|||||||
await testSmartbucket.removeBucket('pushrocks-smartbucket');
|
await testSmartbucket.removeBucket('pushrocks-smartbucket');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should get a bucket', async () => {
|
||||||
|
myBucket = await testSmartbucket.getBucketByName('smartbucket');
|
||||||
|
expect(myBucket).to.be.instanceOf(smartbucket.Bucket);
|
||||||
|
expect(myBucket.name).to.equal('smartbucket');
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should store data in bucket', async () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -2,7 +2,7 @@ import * as plugins from './smartbucket.plugins';
|
|||||||
import { SmartBucket } from './smartbucket.classes.smartbucket';
|
import { SmartBucket } from './smartbucket.classes.smartbucket';
|
||||||
|
|
||||||
export class Bucket {
|
export class Bucket {
|
||||||
public static async createFromName(smartbucketRef: SmartBucket, bucketNameArg: string) {
|
public static async getBucketByName(smartbucketRef: SmartBucket, bucketNameArg: string) {
|
||||||
const buckets = await smartbucketRef.minioClient.listBuckets();
|
const buckets = await smartbucketRef.minioClient.listBuckets();
|
||||||
const foundBucket = buckets.find(bucket => {
|
const foundBucket = buckets.find(bucket => {
|
||||||
return bucket.name === bucketNameArg;
|
return bucket.name === bucketNameArg;
|
||||||
@ -12,13 +12,32 @@ export class Bucket {
|
|||||||
console.log(`bucket with name ${bucketNameArg} exists.`)
|
console.log(`bucket with name ${bucketNameArg} exists.`)
|
||||||
console.log(`Taking this as base for new Bucket instance`);
|
console.log(`Taking this as base for new Bucket instance`);
|
||||||
return new this(smartbucketRef, bucketNameArg);
|
return new this(smartbucketRef, bucketNameArg);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async createBucketByName(smartbucketRef: SmartBucket, bucketName: string) {
|
||||||
|
await smartbucketRef.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e));
|
||||||
|
return new Bucket(smartbucketRef, bucketName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async removeBucketByName(smartbucketRef: SmartBucket, bucketName: string) {
|
||||||
|
await smartbucketRef.minioClient.removeBucket(bucketName).catch(e => console.log(e));
|
||||||
|
}
|
||||||
|
|
||||||
public smartbucketRef: SmartBucket;
|
public smartbucketRef: SmartBucket;
|
||||||
public name: string;
|
public name: string;
|
||||||
|
|
||||||
constructor(smartbucketRef: SmartBucket, bucketName: string) {
|
constructor(smartbucketRef: SmartBucket, bucketName: string) {
|
||||||
this.smartbucketRef = smartbucketRef;
|
this.smartbucketRef = smartbucketRef;
|
||||||
this.name = bucketName;
|
this.name = bucketName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* store file
|
||||||
|
*/
|
||||||
|
public store(fileName:) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,15 +26,16 @@ export class SmartBucket {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async createBucket(bucketName: string) {
|
public async createBucket(bucketNameArg: string) {
|
||||||
await this.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e));
|
const bucket = await Bucket.createBucketByName(this, bucketNameArg);
|
||||||
|
return bucket;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeBucket(bucketName: string) {
|
public async removeBucket(bucketName: string) {
|
||||||
await this.minioClient.removeBucket(bucketName).catch(e => console.log(e));
|
await Bucket.removeBucketByName(this, bucketName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getBucket(bucketName: string) {
|
public async getBucketByName(bucketName: string) {
|
||||||
return Bucket.getFromName(this, bucketName);
|
return Bucket.getBucketByName(this, bucketName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user