From caf0566020622fc3a9999db88c6c0b1b66d0528b Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Tue, 15 Oct 2019 19:23:06 +0200 Subject: [PATCH] fix(core): update --- test/test.ts | 13 ++++++++++++- ts/smartbucket.classes.bucket.ts | 21 ++++++++++++++++++++- ts/smartbucket.classes.smartbucket.ts | 11 ++++++----- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/test/test.ts b/test/test.ts index 68639a0..4129c68 100644 --- a/test/test.ts +++ b/test/test.ts @@ -6,6 +6,7 @@ import * as smartbucket from '../ts/index'; const testQenv = new Qenv('./', './.nogit/'); let testSmartbucket: smartbucket.SmartBucket; +let myBucket: smartbucket.Bucket; tap.test('should create a valid smartbucket', async () => { 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'); }); @@ -23,4 +24,14 @@ tap.skip.test('should remove testbucket', async () => { 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(); diff --git a/ts/smartbucket.classes.bucket.ts b/ts/smartbucket.classes.bucket.ts index 4bba3ce..3da9f75 100644 --- a/ts/smartbucket.classes.bucket.ts +++ b/ts/smartbucket.classes.bucket.ts @@ -2,7 +2,7 @@ import * as plugins from './smartbucket.plugins'; import { SmartBucket } from './smartbucket.classes.smartbucket'; 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 foundBucket = buckets.find(bucket => { return bucket.name === bucketNameArg; @@ -12,13 +12,32 @@ export class Bucket { console.log(`bucket with name ${bucketNameArg} exists.`) console.log(`Taking this as base for new Bucket instance`); 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 name: string; + constructor(smartbucketRef: SmartBucket, bucketName: string) { this.smartbucketRef = smartbucketRef; this.name = bucketName; } + + /** + * store file + */ + public store(fileName:) { + + } } diff --git a/ts/smartbucket.classes.smartbucket.ts b/ts/smartbucket.classes.smartbucket.ts index 1e32f0f..efa0d88 100644 --- a/ts/smartbucket.classes.smartbucket.ts +++ b/ts/smartbucket.classes.smartbucket.ts @@ -26,15 +26,16 @@ export class SmartBucket { }); } - public async createBucket(bucketName: string) { - await this.minioClient.makeBucket(bucketName, 'ams3').catch(e => console.log(e)); + public async createBucket(bucketNameArg: string) { + const bucket = await Bucket.createBucketByName(this, bucketNameArg); + return bucket; } 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) { - return Bucket.getFromName(this, bucketName); + public async getBucketByName(bucketName: string) { + return Bucket.getBucketByName(this, bucketName); } }