2.0.x fixes
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
import crypto from 'crypto';
|
||||
import blake2 from 'blake2';
|
||||
import fs from 'fs';
|
||||
import { Uint64BE } from 'int64-buffer';
|
||||
|
||||
import * as repertory from '../index.js';
|
||||
import connection from '../networking/connection';
|
||||
import connection_pool from '../networking/connection_pool';
|
||||
|
||||
const TEST_HOST = process.env.TEST_HOST || 'localhost';
|
||||
const TEST_PASSWORD = process.env.TEST_PASSWORD || '';
|
||||
const TEST_PASSWORD = process.env.TEST_PASSWORD || 'cow_moose_doge_chicken';
|
||||
const TEST_PORT = process.env.TEST_PORT || 20000;
|
||||
|
||||
const calculate_sha256 = (path) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const hash = crypto.createHash('sha256');
|
||||
const hash = blake2.createHash('blake2b', { digestLength: 32 });
|
||||
|
||||
fs.createReadStream(path)
|
||||
.on('data', (data) => hash.update(data))
|
||||
@@ -35,56 +34,16 @@ const test_connection = (conn, should_be_connected) => {
|
||||
};
|
||||
|
||||
test('can create a connection to repertory api', async () => {
|
||||
console.log('TEST_PASSWORD', TEST_PASSWORD);
|
||||
const conn = await repertory.connect(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
test_connection(conn, true);
|
||||
|
||||
await conn.disconnect();
|
||||
});
|
||||
|
||||
test('create_pool returns a connection if pool size is <=1', async () => {
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const conn = await repertory.create_pool(
|
||||
i,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
expect(conn).toBeInstanceOf(connection);
|
||||
test_connection(conn, true);
|
||||
|
||||
await conn.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
test('can create a connection pool', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
console.log(conn);
|
||||
expect(conn).toBeInstanceOf(connection_pool);
|
||||
expect(conn.host_or_ip).toEqual(TEST_HOST);
|
||||
expect(conn.port).toEqual(TEST_PORT);
|
||||
expect(conn.password).toEqual(TEST_PASSWORD);
|
||||
expect(conn.shutdown).toEqual(false);
|
||||
expect(conn.pool._pool.max).toEqual(2);
|
||||
expect(conn.pool._pool.min).toEqual(2);
|
||||
|
||||
await conn.disconnect();
|
||||
});
|
||||
|
||||
test('can get drive information using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
const di = await api.get_drive_information();
|
||||
console.log(di);
|
||||
|
||||
expect(di.free).toBeDefined();
|
||||
expect(di.total).toBeDefined();
|
||||
@@ -94,12 +53,7 @@ test('can get drive information using api', async () => {
|
||||
});
|
||||
|
||||
test('can create and remove a directory using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
expect(await api.directory.create('/repertory_js')).toEqual(0);
|
||||
expect(await api.directory.exists('/repertory_js')).toEqual(true);
|
||||
@@ -110,12 +64,7 @@ test('can create and remove a directory using api', async () => {
|
||||
});
|
||||
|
||||
test('can get directory list and snapshot using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
|
||||
const test_results = async (remote_path, page_count, get_page) => {
|
||||
@@ -127,10 +76,11 @@ test('can get directory list and snapshot using api', async () => {
|
||||
console.log(items);
|
||||
|
||||
expect(items.length).toBeGreaterThanOrEqual(2);
|
||||
expect(items[0].directory).toBeTruthy();
|
||||
expect(items[0].path).toEqual('.');
|
||||
expect(items[1].directory).toBeTruthy();
|
||||
expect(items[1].path).toEqual('..');
|
||||
expect(items[0].Directory).toBeTruthy();
|
||||
expect(items[0].ApiPath).toEqual('.');
|
||||
|
||||
expect(items[1].Directory).toBeTruthy();
|
||||
expect(items[1].ApiPath).toEqual('..');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -153,12 +103,7 @@ test('can get directory list and snapshot using api', async () => {
|
||||
});
|
||||
|
||||
test('can create, close and remove a file using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
const f = await api.file.create_or_open('/repertory_file.dat');
|
||||
console.log(f);
|
||||
@@ -175,12 +120,7 @@ test('can create, close and remove a file using api', async () => {
|
||||
});
|
||||
|
||||
test('can open, close and remove a file using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
let f = await api.file.create_or_open('/repertory_file.dat');
|
||||
expect(await f.close()).toEqual(0);
|
||||
@@ -200,12 +140,7 @@ test('can open, close and remove a file using api', async () => {
|
||||
});
|
||||
|
||||
test('can write to and read from a file using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
const f = await api.file.create_or_open('/repertory_file.dat');
|
||||
|
||||
@@ -227,12 +162,7 @@ test('can write to and read from a file using api', async () => {
|
||||
});
|
||||
|
||||
test('can truncate a file using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
const f = await api.file.create_or_open('/repertory_file.dat');
|
||||
|
||||
@@ -253,12 +183,7 @@ test('can upload and download a file using api', async () => {
|
||||
fs.unlinkSync('repertory_test.dat');
|
||||
} catch {}
|
||||
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
expect(
|
||||
await api.file.upload('test.dat', '/repertory_test.dat', (l, r, p, c) => {
|
||||
@@ -289,12 +214,7 @@ test('can upload and download a file using api', async () => {
|
||||
}, 60000);
|
||||
|
||||
test('can download and overwrite a file using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
expect(
|
||||
await api.file.upload('test.dat', '/repertory_test.dat', (l, r, p, c) => {
|
||||
@@ -330,12 +250,7 @@ test('can download and overwrite a file using api', async () => {
|
||||
}, 60000);
|
||||
|
||||
test('download fails if overwrite is false using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
expect(
|
||||
await api.file.upload('test.dat', '/repertory_test.dat', (l, r, p, c) => {
|
||||
@@ -371,12 +286,7 @@ test('download fails if overwrite is false using api', async () => {
|
||||
}, 60000);
|
||||
|
||||
test('can upload and overwrite a file using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
expect(
|
||||
await api.file.upload('test.dat', '/repertory_test.dat', (l, r, p, c) => {
|
||||
@@ -401,12 +311,7 @@ test('can upload and overwrite a file using api', async () => {
|
||||
}, 60000);
|
||||
|
||||
test('upload fails if overwrite is false using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
expect(
|
||||
await api.file.upload('test.dat', '/repertory_test.dat', (l, r, p, c) => {
|
||||
@@ -431,12 +336,7 @@ test('upload fails if overwrite is false using api', async () => {
|
||||
}, 60000);
|
||||
|
||||
test('can resume download using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
expect(
|
||||
await api.file.upload('test.dat', '/repertory_test.dat', (l, r, p, c) => {
|
||||
@@ -474,12 +374,7 @@ test('can resume download using api', async () => {
|
||||
}, 60000);
|
||||
|
||||
test('can resume upload using api', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
|
||||
const fd = fs.openSync('test.dat', 'r');
|
||||
@@ -524,24 +419,14 @@ test('can resume upload using api', async () => {
|
||||
}, 60000);
|
||||
|
||||
test('exists returns false if directory is not found', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
expect(await api.directory.exists('/cow')).toEqual(false);
|
||||
await conn.disconnect();
|
||||
});
|
||||
|
||||
test('exists returns false if file is not found', async () => {
|
||||
const conn = await repertory.create_pool(
|
||||
2,
|
||||
TEST_HOST,
|
||||
TEST_PORT,
|
||||
TEST_PASSWORD
|
||||
);
|
||||
const conn = await repertory.create(TEST_HOST, TEST_PORT, TEST_PASSWORD);
|
||||
const api = repertory.create_api(conn);
|
||||
expect(await api.file.exists('/cow')).toEqual(false);
|
||||
await conn.disconnect();
|
||||
|
||||
Reference in New Issue
Block a user