smartbucket/test/test.ts

74 lines
2.4 KiB
TypeScript
Raw Normal View History

2019-07-07 08:48:24 +00:00
import { expect, tap } from '@pushrocks/tapbundle';
2019-10-15 12:16:28 +00:00
import { Qenv } from '@pushrocks/qenv';
2018-09-14 16:07:20 +00:00
import * as smartbucket from '../ts/index';
2018-03-30 17:42:14 +00:00
2019-10-15 12:16:28 +00:00
const testQenv = new Qenv('./', './.nogit/');
let testSmartbucket: smartbucket.SmartBucket;
2019-10-15 17:23:06 +00:00
let myBucket: smartbucket.Bucket;
2019-10-16 17:11:28 +00:00
let baseDirectory: smartbucket.Directory;
2019-10-15 12:16:28 +00:00
tap.test('should create a valid smartbucket', async () => {
testSmartbucket = new smartbucket.SmartBucket({
accessKey: testQenv.getEnvVarOnDemand('S3_KEY'),
accessSecret: testQenv.getEnvVarOnDemand('S3_SECRET'),
endpoint: 'ams3.digitaloceanspaces.com'
});
});
2019-10-15 17:23:06 +00:00
tap.skip.test('should create testbucket', async () => {
2019-10-15 12:16:28 +00:00
await testSmartbucket.createBucket('smartbucket');
});
tap.skip.test('should remove testbucket', async () => {
await testSmartbucket.removeBucket('pushrocks-smartbucket');
2018-09-14 16:07:20 +00:00
});
2018-03-30 17:42:14 +00:00
2019-10-15 17:23:06 +00:00
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');
});
2019-10-16 16:12:18 +00:00
// Fast operations
tap.test('should store data in bucket fast', async () => {
await myBucket.fastStore('hithere/socool.txt', 'hi there!');
2019-10-15 17:23:06 +00:00
});
2019-10-16 13:21:02 +00:00
tap.test('should get data in bucket', async () => {
2019-10-16 16:12:18 +00:00
const fileString = await myBucket.fastGet('hithere/socool.txt');
2019-10-16 13:21:02 +00:00
console.log(fileString);
});
tap.test('should delete data in bucket', async () => {
2019-10-16 16:12:18 +00:00
await myBucket.fastRemove('hithere/socool.txt');
2019-10-16 13:21:02 +00:00
});
2019-10-16 17:11:28 +00:00
// fs operations
tap.test('prepare for directory style tests', async () => {
await myBucket.fastStore('dir1/file1.txt', 'dir1/file1.txt content');
await myBucket.fastStore('dir1/file2.txt', 'dir1/file2.txt content');
await myBucket.fastStore('dir2/file1.txt', 'dir2/file1.txt content');
await myBucket.fastStore('dir3/file1.txt', 'dir3/file1.txt content');
await myBucket.fastStore('file1.txt', 'file1 content');
});
tap.test('should get base directory', async () => {
baseDirectory = await myBucket.getBaseDirectory();
const directories = await baseDirectory.listDirectories();
expect(directories.length).to.equal(3);
const files = await baseDirectory.listFiles();
});
tap.test('clean up directory style tests', async () => {
await myBucket.fastRemove('dir1/file1.txt');
await myBucket.fastRemove('dir1/file2.txt');
await myBucket.fastRemove('dir2/file1.txt');
await myBucket.fastRemove('dir3/file1.txt');
await myBucket.fastRemove('file1.txt');
});
2018-09-14 16:07:20 +00:00
tap.start();