2023-11-03 00:36:11 +00:00
|
|
|
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
|
|
|
import { Qenv } from '@push.rocks/qenv';
|
2019-10-15 12:16:28 +00:00
|
|
|
|
2022-03-30 23:45:46 +00:00
|
|
|
import * as smartbucket from '../ts/index.js';
|
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({
|
2023-11-03 00:36:11 +00:00
|
|
|
accessKey: await testQenv.getEnvVarOnDemand('S3_KEY'),
|
|
|
|
accessSecret: await testQenv.getEnvVarOnDemand('S3_SECRET'),
|
2021-12-18 00:00:07 +00:00
|
|
|
endpoint: 's3.eu-central-1.wasabisys.com',
|
2019-10-15 12:16:28 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-15 17:23:06 +00:00
|
|
|
tap.skip.test('should create testbucket', async () => {
|
2021-12-18 00:00:07 +00:00
|
|
|
// await testSmartbucket.createBucket('testzone');
|
2019-10-15 12:16:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.skip.test('should remove testbucket', async () => {
|
2021-12-18 00:00:07 +00:00
|
|
|
// await testSmartbucket.removeBucket('testzone');
|
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 () => {
|
2019-10-18 10:22:42 +00:00
|
|
|
myBucket = await testSmartbucket.getBucketByName('testzone');
|
2022-03-30 23:45:46 +00:00
|
|
|
expect(myBucket).toBeInstanceOf(smartbucket.Bucket);
|
|
|
|
expect(myBucket.name).toEqual('testzone');
|
2019-10-15 17:23:06 +00:00
|
|
|
});
|
|
|
|
|
2019-10-16 16:12:18 +00:00
|
|
|
// Fast operations
|
|
|
|
tap.test('should store data in bucket fast', async () => {
|
2024-05-05 17:52:50 +00:00
|
|
|
await myBucket.fastPut('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');
|
2020-02-21 23:06:47 +00:00
|
|
|
const fileStringStream = await myBucket.fastGetStream('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 () => {
|
2024-05-05 17:52:50 +00:00
|
|
|
await myBucket.fastPut('dir1/file1.txt', 'dir1/file1.txt content');
|
|
|
|
await myBucket.fastPut('dir1/file2.txt', 'dir1/file2.txt content');
|
|
|
|
await myBucket.fastPut('dir2/file1.txt', 'dir2/file1.txt content');
|
|
|
|
await myBucket.fastPut('dir3/file1.txt', 'dir3/file1.txt content');
|
|
|
|
await myBucket.fastPut('dir3/dir4/file1.txt', 'dir3/dir4/file1.txt content');
|
|
|
|
await myBucket.fastPut('file1.txt', 'file1 content');
|
2019-10-16 17:11:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should get base directory', async () => {
|
|
|
|
baseDirectory = await myBucket.getBaseDirectory();
|
|
|
|
const directories = await baseDirectory.listDirectories();
|
2019-10-18 13:43:06 +00:00
|
|
|
console.log('Found the following directories:');
|
|
|
|
console.log(directories);
|
2022-03-30 23:45:46 +00:00
|
|
|
expect(directories.length).toEqual(3);
|
2019-10-16 17:11:28 +00:00
|
|
|
const files = await baseDirectory.listFiles();
|
2019-10-18 13:43:06 +00:00
|
|
|
console.log('Found the following files:');
|
2019-10-18 10:34:32 +00:00
|
|
|
console.log(files);
|
2022-03-30 23:45:46 +00:00
|
|
|
expect(files.length).toEqual(1);
|
2019-10-16 17:11:28 +00:00
|
|
|
});
|
|
|
|
|
2019-10-19 22:45:11 +00:00
|
|
|
tap.test('should correctly build paths for sub directories', async () => {
|
2019-10-19 23:18:13 +00:00
|
|
|
const dir4 = await baseDirectory.getSubDirectoryByName('dir3/dir4');
|
2022-03-30 23:45:46 +00:00
|
|
|
expect(dir4).toBeInstanceOf(smartbucket.Directory);
|
2019-10-19 23:18:13 +00:00
|
|
|
const dir4BasePath = dir4.getBasePath();
|
|
|
|
console.log(dir4BasePath);
|
2019-10-19 22:45:11 +00:00
|
|
|
});
|
|
|
|
|
2019-10-16 17:11:28 +00:00
|
|
|
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');
|
2019-10-19 23:18:13 +00:00
|
|
|
await myBucket.fastRemove('dir3/dir4/file1.txt');
|
2019-10-16 17:11:28 +00:00
|
|
|
await myBucket.fastRemove('file1.txt');
|
|
|
|
});
|
|
|
|
|
2018-09-14 16:07:20 +00:00
|
|
|
tap.start();
|