2023-11-03 01:36:11 +01:00
|
|
|
import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
|
|
|
|
import { Qenv } from '@push.rocks/qenv';
|
2019-10-15 14:16:28 +02:00
|
|
|
|
2022-03-31 01:45:46 +02:00
|
|
|
import * as smartbucket from '../ts/index.js';
|
2018-03-30 19:42:14 +02:00
|
|
|
|
2019-10-15 14:16:28 +02:00
|
|
|
const testQenv = new Qenv('./', './.nogit/');
|
|
|
|
|
|
|
|
let testSmartbucket: smartbucket.SmartBucket;
|
2019-10-15 19:23:06 +02:00
|
|
|
let myBucket: smartbucket.Bucket;
|
2019-10-16 19:11:28 +02:00
|
|
|
let baseDirectory: smartbucket.Directory;
|
2019-10-15 14:16:28 +02:00
|
|
|
|
|
|
|
tap.test('should create a valid smartbucket', async () => {
|
|
|
|
testSmartbucket = new smartbucket.SmartBucket({
|
2023-11-03 01:36:11 +01:00
|
|
|
accessKey: await testQenv.getEnvVarOnDemand('S3_KEY'),
|
|
|
|
accessSecret: await testQenv.getEnvVarOnDemand('S3_SECRET'),
|
2024-07-04 18:39:27 +02:00
|
|
|
endpoint: await testQenv.getEnvVarOnDemand('S3_ENDPOINT'),
|
2019-10-15 14:16:28 +02:00
|
|
|
});
|
2024-06-18 18:44:58 +02:00
|
|
|
expect(testSmartbucket).toBeInstanceOf(smartbucket.SmartBucket);
|
|
|
|
myBucket = await testSmartbucket.getBucketByName('testzone');
|
|
|
|
expect(myBucket).toBeInstanceOf(smartbucket.Bucket);
|
|
|
|
expect(myBucket.name).toEqual('testzone');
|
2019-10-15 14:16:28 +02:00
|
|
|
});
|
|
|
|
|
2019-10-15 19:23:06 +02:00
|
|
|
tap.skip.test('should create testbucket', async () => {
|
2024-06-18 18:44:58 +02:00
|
|
|
// await testSmartbucket.createBucket('testzone2');
|
2019-10-15 14:16:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.skip.test('should remove testbucket', async () => {
|
2024-06-18 18:44:58 +02:00
|
|
|
// await testSmartbucket.removeBucket('testzone2');
|
2019-10-15 19:23:06 +02:00
|
|
|
});
|
|
|
|
|
2019-10-16 18:12:18 +02:00
|
|
|
// Fast operations
|
|
|
|
tap.test('should store data in bucket fast', async () => {
|
2024-05-17 18:53:11 +02:00
|
|
|
await myBucket.fastPut({
|
|
|
|
path: 'hithere/socool.txt',
|
|
|
|
contents: 'hi there!',
|
|
|
|
});
|
2019-10-15 19:23:06 +02:00
|
|
|
});
|
|
|
|
|
2019-10-16 15:21:02 +02:00
|
|
|
tap.test('should get data in bucket', async () => {
|
2024-05-17 18:53:11 +02:00
|
|
|
const fileString = await myBucket.fastGet({
|
|
|
|
path: 'hithere/socool.txt',
|
|
|
|
});
|
|
|
|
const fileStringStream = await myBucket.fastGetStream({
|
|
|
|
path: 'hithere/socool.txt',
|
2024-06-03 21:35:08 +02:00
|
|
|
}, 'nodestream');
|
2019-10-16 15:21:02 +02:00
|
|
|
console.log(fileString);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should delete data in bucket', async () => {
|
2024-05-17 18:53:11 +02:00
|
|
|
await myBucket.fastRemove({
|
|
|
|
path: 'hithere/socool.txt',
|
|
|
|
});
|
2019-10-16 15:21:02 +02:00
|
|
|
});
|
|
|
|
|
2019-10-16 19:11:28 +02:00
|
|
|
// fs operations
|
|
|
|
|
|
|
|
tap.test('prepare for directory style tests', async () => {
|
2024-05-17 18:53:11 +02:00
|
|
|
await myBucket.fastPut({
|
|
|
|
path: 'dir1/file1.txt',
|
|
|
|
contents: 'dir1/file1.txt content',
|
|
|
|
});
|
|
|
|
await myBucket.fastPut({
|
|
|
|
path: 'dir1/file2.txt',
|
|
|
|
contents: 'dir1/file2.txt content',
|
|
|
|
});
|
|
|
|
await myBucket.fastPut({
|
|
|
|
path: 'dir2/file1.txt',
|
|
|
|
contents: 'dir2/file1.txt content',
|
|
|
|
});
|
|
|
|
await myBucket.fastPut({
|
|
|
|
path: 'dir3/file1.txt',
|
|
|
|
contents: 'dir3/file1.txt content',
|
|
|
|
});
|
|
|
|
await myBucket.fastPut({
|
|
|
|
path: 'dir3/dir4/file1.txt',
|
|
|
|
contents: 'dir3/dir4/file1.txt content',
|
|
|
|
});
|
|
|
|
await myBucket.fastPut({
|
2024-05-27 12:56:25 +02:00
|
|
|
path: '/file1.txt',
|
2024-05-17 18:53:11 +02:00
|
|
|
contents: 'file1 content',
|
|
|
|
});
|
2019-10-16 19:11:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should get base directory', async () => {
|
|
|
|
baseDirectory = await myBucket.getBaseDirectory();
|
|
|
|
const directories = await baseDirectory.listDirectories();
|
2019-10-18 15:43:06 +02:00
|
|
|
console.log('Found the following directories:');
|
|
|
|
console.log(directories);
|
2022-03-31 01:45:46 +02:00
|
|
|
expect(directories.length).toEqual(3);
|
2019-10-16 19:11:28 +02:00
|
|
|
const files = await baseDirectory.listFiles();
|
2019-10-18 15:43:06 +02:00
|
|
|
console.log('Found the following files:');
|
2019-10-18 12:34:32 +02:00
|
|
|
console.log(files);
|
2022-03-31 01:45:46 +02:00
|
|
|
expect(files.length).toEqual(1);
|
2019-10-16 19:11:28 +02:00
|
|
|
});
|
|
|
|
|
2019-10-20 00:45:11 +02:00
|
|
|
tap.test('should correctly build paths for sub directories', async () => {
|
2019-10-20 01:18:13 +02:00
|
|
|
const dir4 = await baseDirectory.getSubDirectoryByName('dir3/dir4');
|
2022-03-31 01:45:46 +02:00
|
|
|
expect(dir4).toBeInstanceOf(smartbucket.Directory);
|
2019-10-20 01:18:13 +02:00
|
|
|
const dir4BasePath = dir4.getBasePath();
|
|
|
|
console.log(dir4BasePath);
|
2019-10-20 00:45:11 +02:00
|
|
|
});
|
|
|
|
|
2019-10-16 19:11:28 +02:00
|
|
|
tap.test('clean up directory style tests', async () => {
|
2024-05-17 18:53:11 +02:00
|
|
|
await myBucket.fastRemove({
|
|
|
|
path: 'dir1/file1.txt',
|
|
|
|
});
|
|
|
|
await myBucket.fastRemove({
|
|
|
|
path: 'dir1/file2.txt',
|
|
|
|
});
|
|
|
|
await myBucket.fastRemove({
|
|
|
|
path: 'dir2/file1.txt',
|
|
|
|
});
|
|
|
|
await myBucket.fastRemove({ path: 'dir3/file1.txt' });
|
|
|
|
await myBucket.fastRemove({ path: 'dir3/dir4/file1.txt' });
|
|
|
|
await myBucket.fastRemove({ path: 'file1.txt' });
|
2019-10-16 19:11:28 +02:00
|
|
|
});
|
|
|
|
|
2018-09-14 18:07:20 +02:00
|
|
|
tap.start();
|