core-3nweb-client-lib 0.44.12 → 0.45.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/core/asmail/msg/opener.js +1 -1
- package/build/core/asmail/msg/packer.js +1 -1
- package/build/core/index.d.ts +2 -2
- package/build/core/keyring/correspondent-keys.js +1 -1
- package/build/core/keyring/index.js +1 -1
- package/build/core/startup/sign-in.d.ts +1 -1
- package/build/core/startup/sign-up.d.ts +1 -1
- package/build/core/storage/index.d.ts +1 -1
- package/build/lib-client/doh.d.ts +2 -0
- package/build/lib-client/doh.js +68 -0
- package/build/lib-client/key-derivation.d.ts +1 -1
- package/build/lib-client/request-utils.js +1 -1
- package/build/lib-client/service-checks.js +3 -11
- package/build/lib-client/service-locator.d.ts +10 -2
- package/build/lib-client/service-locator.js +40 -27
- package/build/lib-client/xsp-fs/node-persistence.js +1 -1
- package/build/lib-index.d.ts +1 -0
- package/build/lib-index.js +3 -1
- package/build/tests/caps-api/asmail/specs/events.d.ts +2 -0
- package/build/tests/caps-api/asmail/specs/events.js +63 -0
- package/build/tests/caps-api/asmail/specs/send-to-wrong-address.d.ts +2 -0
- package/build/tests/caps-api/asmail/specs/send-to-wrong-address.js +68 -0
- package/build/tests/caps-api/asmail/specs/send-with-attacment-from-storage.d.ts +2 -0
- package/build/tests/caps-api/asmail/specs/send-with-attacment-from-storage.js +259 -0
- package/build/tests/caps-api/asmail/specs/send-without-attachments.d.ts +2 -0
- package/build/tests/caps-api/asmail/specs/send-without-attachments.js +90 -0
- package/build/tests/caps-api/asmail/test-utils.d.ts +12 -0
- package/build/tests/caps-api/asmail/test-utils.js +60 -0
- package/build/tests/caps-api/asmail.js +86 -0
- package/build/tests/caps-api/file-sink-checks/different-cases.d.ts +2 -0
- package/build/tests/caps-api/file-sink-checks/different-cases.js +47 -0
- package/build/tests/caps-api/file-sink-checks/splice.d.ts +2 -0
- package/build/tests/caps-api/file-sink-checks/splice.js +122 -0
- package/build/tests/caps-api/file-sink-checks/truncate.d.ts +2 -0
- package/build/tests/caps-api/file-sink-checks/truncate.js +122 -0
- package/build/tests/caps-api/fs-checks/local-to-synced-linking/link.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/local-to-synced-linking/link.js +82 -0
- package/build/tests/caps-api/fs-checks/local-to-synced-linking/reversed-linking.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/local-to-synced-linking/reversed-linking.js +50 -0
- package/build/tests/caps-api/fs-checks/not-versioned/deleteFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/deleteFile.js +73 -0
- package/build/tests/caps-api/fs-checks/not-versioned/deleteFolder.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/deleteFolder.js +75 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getByteSink.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getByteSink.js +96 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getByteSource.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getByteSource.js +67 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getXAttr.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/getXAttr.js +77 -0
- package/build/tests/caps-api/fs-checks/not-versioned/link.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/link.js +115 -0
- package/build/tests/caps-api/fs-checks/not-versioned/listFolder.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/listFolder.js +129 -0
- package/build/tests/caps-api/fs-checks/not-versioned/listXAttrs.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/listXAttrs.js +73 -0
- package/build/tests/caps-api/fs-checks/not-versioned/makeFolder.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/makeFolder.js +95 -0
- package/build/tests/caps-api/fs-checks/not-versioned/move.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/move.js +127 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readBytes.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readBytes.js +80 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readJSONFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readJSONFile.js +59 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readLink.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readLink.js +39 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readTxtFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readTxtFile.js +54 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readonlyFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readonlyFile.js +55 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readonlySubRoot.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/readonlySubRoot.js +55 -0
- package/build/tests/caps-api/fs-checks/not-versioned/select.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/select.js +119 -0
- package/build/tests/caps-api/fs-checks/not-versioned/stat.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/stat.js +96 -0
- package/build/tests/caps-api/fs-checks/not-versioned/updateXAttrs.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/updateXAttrs.js +126 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writableFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writableFile.js +79 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writableSubRoot.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writableSubRoot.js +90 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeBytes.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeBytes.js +137 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeJSONFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeJSONFile.js +101 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeTxtFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/not-versioned/writeTxtFile.js +100 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/startUpload.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/startUpload.js +187 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/stat.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/stat.js +70 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/status.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/status.js +53 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/upload.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-on-one-dev/upload.js +194 -0
- package/build/tests/caps-api/fs-checks/sync-with-two-devs/conflicts.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-with-two-devs/conflicts.js +396 -0
- package/build/tests/caps-api/fs-checks/sync-with-two-devs/update-propagation.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/sync-with-two-devs/update-propagation.js +229 -0
- package/build/tests/caps-api/fs-checks/test-utils.d.ts +34 -0
- package/build/tests/caps-api/fs-checks/test-utils.js +95 -0
- package/build/tests/caps-api/fs-checks/versioned/archiveCurrent.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/archiveCurrent.js +73 -0
- package/build/tests/caps-api/fs-checks/versioned/getByteSink.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/getByteSink.js +122 -0
- package/build/tests/caps-api/fs-checks/versioned/getByteSource.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/getByteSource.js +71 -0
- package/build/tests/caps-api/fs-checks/versioned/listFolder.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/listFolder.js +109 -0
- package/build/tests/caps-api/fs-checks/versioned/listVersions.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/listVersions.js +48 -0
- package/build/tests/caps-api/fs-checks/versioned/readBytes.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/readBytes.js +90 -0
- package/build/tests/caps-api/fs-checks/versioned/readJSONFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/readJSONFile.js +60 -0
- package/build/tests/caps-api/fs-checks/versioned/readTxtFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/readTxtFile.js +56 -0
- package/build/tests/caps-api/fs-checks/versioned/stat.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/stat.js +80 -0
- package/build/tests/caps-api/fs-checks/versioned/watchFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/watchFile.js +64 -0
- package/build/tests/caps-api/fs-checks/versioned/writeBytes.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/writeBytes.js +128 -0
- package/build/tests/caps-api/fs-checks/versioned/writeJSONFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/writeJSONFile.js +111 -0
- package/build/tests/caps-api/fs-checks/versioned/writeTxtFile.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/versioned/writeTxtFile.js +107 -0
- package/build/tests/caps-api/fs-checks/with-core-restarts/xattrs.d.ts +2 -0
- package/build/tests/caps-api/fs-checks/with-core-restarts/xattrs.js +50 -0
- package/build/tests/caps-api/keyrings.js +69 -0
- package/build/tests/caps-api/mailerid.d.ts +1 -0
- package/build/tests/caps-api/mailerid.js +59 -0
- package/build/tests/caps-api/startup/signin-empty-cache.d.ts +1 -0
- package/build/tests/caps-api/startup/signin-empty-cache.js +108 -0
- package/build/tests/caps-api/startup/signin-with-cache.d.ts +1 -0
- package/build/tests/caps-api/startup/signin-with-cache.js +83 -0
- package/build/tests/caps-api/startup/signup-with-token.d.ts +1 -0
- package/build/tests/caps-api/startup/signup-with-token.js +53 -0
- package/build/tests/caps-api/startup/signup.d.ts +1 -0
- package/build/tests/caps-api/startup/signup.js +86 -0
- package/build/tests/caps-api/storage.d.ts +1 -0
- package/build/tests/caps-api/storage.js +225 -0
- package/build/tests/computer.3nweb.core/id-manager.d.ts +1 -0
- package/build/tests/computer.3nweb.core/id-manager.js +78 -0
- package/build/tests/computer.3nweb.core/inbox/msg-indexing.d.ts +1 -0
- package/build/tests/computer.3nweb.core/inbox/msg-indexing.js +145 -0
- package/build/tests/computer.3nweb.core/keyrings.d.ts +1 -0
- package/build/tests/computer.3nweb.core/keyrings.js +64 -0
- package/build/tests/computer.3nweb.core/test-utils.d.ts +21 -0
- package/build/tests/computer.3nweb.core/test-utils.js +92 -0
- package/build/tests/jasmine.d.ts +1 -0
- package/build/tests/jasmine.js +45 -0
- package/build/tests/libs-for-tests/bytes-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/bytes-equal.js +32 -0
- package/build/tests/libs-for-tests/caps-ipc-wrap.d.ts +11 -0
- package/build/tests/libs-for-tests/caps-ipc-wrap.js +55 -0
- package/build/tests/libs-for-tests/core-runner.d.ts +39 -0
- package/build/tests/libs-for-tests/core-runner.js +231 -0
- package/build/tests/libs-for-tests/jasmine-utils.d.ts +13 -0
- package/build/tests/libs-for-tests/jasmine-utils.js +110 -0
- package/build/tests/libs-for-tests/json-equal.d.ts +1 -0
- package/build/tests/libs-for-tests/json-equal.js +78 -0
- package/build/tests/libs-for-tests/services-runner.d.ts +18 -0
- package/build/tests/libs-for-tests/services-runner.js +64 -0
- package/build/tests/libs-for-tests/setups.d.ts +51 -0
- package/build/tests/libs-for-tests/setups.js +305 -0
- package/build/tests/libs-for-tests/spec-module.d.ts +16 -0
- package/build/tests/libs-for-tests/spec-module.js +92 -0
- package/build/tests/libs-for-tests/startup.d.ts +1 -0
- package/build/tests/libs-for-tests/startup.js +29 -0
- package/build/tests/libs-for-tests/watching.d.ts +7 -0
- package/build/tests/libs-for-tests/watching.js +33 -0
- package/build/tests/units/canonical-address.d.ts +1 -0
- package/build/tests/units/canonical-address.js +41 -0
- package/build/tests/units/device-fs.d.ts +1 -0
- package/build/tests/units/device-fs.js +70 -0
- package/build/tests/units/folder-node-serialization.d.ts +1 -0
- package/build/tests/units/folder-node-serialization.js +74 -0
- package/build/tests/units/mid-sigs-NaCl-Ed.d.ts +1 -0
- package/build/tests/units/mid-sigs-NaCl-Ed.js +123 -0
- package/build/tests/units/number-line.d.ts +1 -0
- package/build/tests/units/number-line.js +63 -0
- package/build/tests/units/obj-folders.d.ts +1 -0
- package/build/tests/units/obj-folders.js +152 -0
- package/package.json +11 -3
- package/postinstall.js +1 -1
- package/build/cryptors.d.ts +0 -1
- package/build/cryptors.js +0 -34
- package/build/lib-client/cryptor/cryptor-in-worker.d.ts +0 -20
- package/build/lib-client/cryptor/cryptor-in-worker.js +0 -357
- package/build/lib-client/cryptor/cryptor-wasm.js +0 -1
- package/build/lib-client/cryptor/cryptor.d.ts +0 -30
- package/build/lib-client/cryptor/cryptor.js +0 -44
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-js.d.ts +0 -2
- package/build/lib-client/cryptor/in-proc-js.js +0 -57
- package/build/lib-client/cryptor/in-proc-wasm.d.ts +0 -2
- package/build/lib-client/cryptor/in-proc-wasm.js +0 -176
- package/build/lib-client/cryptor/serialization-for-wasm.d.ts +0 -35
- package/build/lib-client/cryptor/serialization-for-wasm.js +0 -57
- package/build/lib-client/cryptor/wasm-mp1-modules.d.ts +0 -5
- package/build/lib-client/cryptor/wasm-mp1-modules.js +0 -78
- package/build/lib-client/cryptor/worker-js.js +0 -131
- package/build/lib-client/cryptor/worker-wasm.js +0 -37
- package/build/protos/cryptor.proto.js +0 -1804
- /package/build/lib-client/{cryptor/cryptor-work-labels.d.ts → cryptor-work-labels.d.ts} +0 -0
- /package/build/lib-client/{cryptor/cryptor-work-labels.js → cryptor-work-labels.js} +0 -0
- /package/build/{lib-client/cryptor/worker-js.d.ts → tests/caps-api/asmail.d.ts} +0 -0
- /package/build/{lib-client/cryptor/worker-wasm.d.ts → tests/caps-api/keyrings.d.ts} +0 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2020 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.specs = void 0;
|
|
20
|
+
const random_node_1 = require("../../../lib-common/random-node");
|
|
21
|
+
const bytes_equal_1 = require("../../libs-for-tests/bytes-equal");
|
|
22
|
+
exports.specs = {
|
|
23
|
+
description: 'gives file sinks, able to splice file content',
|
|
24
|
+
its: []
|
|
25
|
+
};
|
|
26
|
+
let it = { expectation: 'of a newly created file' };
|
|
27
|
+
it.func = async function (s) {
|
|
28
|
+
const { testFS } = s;
|
|
29
|
+
function expectSection(l, sectionInd, src, ofs, len) {
|
|
30
|
+
const section = l.sections[sectionInd];
|
|
31
|
+
if (section) {
|
|
32
|
+
expect(section.src).withContext(`wrong source in section ${sectionInd}`).toBe(src);
|
|
33
|
+
expect(section.ofs).withContext(`wrong offset in section ${sectionInd}`).toBe(ofs);
|
|
34
|
+
expect(section.len).withContext(`wrong length in section ${sectionInd}`).toBe(len);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
fail(`section index ${sectionInd} is not in layout with ${l.sections.length} sections`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const fName = 'file1';
|
|
41
|
+
const sink = await testFS.getByteSink(fName, { create: true, exclusive: true });
|
|
42
|
+
let size = await sink.getSize();
|
|
43
|
+
expect(size).toBe(0);
|
|
44
|
+
let layout = await sink.showLayout();
|
|
45
|
+
expect(Array.isArray(layout.sections)).toBeTruthy();
|
|
46
|
+
expect(layout.sections.length).toBe(0);
|
|
47
|
+
const chunk1 = (0, random_node_1.bytesSync)(10000);
|
|
48
|
+
await sink.splice(0, chunk1.length, chunk1);
|
|
49
|
+
size = await sink.getSize();
|
|
50
|
+
expect(size).toBe(10000);
|
|
51
|
+
layout = await sink.showLayout();
|
|
52
|
+
expect(layout.sections.length).toBe(1);
|
|
53
|
+
expectSection(layout, 0, 'new', 0, size);
|
|
54
|
+
const chunk2 = (0, random_node_1.bytesSync)(100);
|
|
55
|
+
await sink.splice(11000, 0, chunk2);
|
|
56
|
+
size = await sink.getSize();
|
|
57
|
+
layout = await sink.showLayout();
|
|
58
|
+
if (testFS.type === 'device') {
|
|
59
|
+
expect(layout.sections.length).toBe(1);
|
|
60
|
+
expectSection(layout, 0, 'new', 0, size);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
expect(layout.sections.length).toBe(3);
|
|
64
|
+
expectSection(layout, 0, 'new', 0, 10000);
|
|
65
|
+
expectSection(layout, 1, 'empty', 10000, 1000);
|
|
66
|
+
expectSection(layout, 2, 'new', 11000, 100);
|
|
67
|
+
}
|
|
68
|
+
await sink.done();
|
|
69
|
+
const content = await testFS.readBytes(fName);
|
|
70
|
+
expect(content.length).toBe(size);
|
|
71
|
+
expect((0, bytes_equal_1.bytesEqual)(content.subarray(0, 10000), chunk1)).toBe(true);
|
|
72
|
+
expect((0, bytes_equal_1.bytesEqual)(content.subarray(11000), chunk2)).toBe(true);
|
|
73
|
+
};
|
|
74
|
+
exports.specs.its.push(it);
|
|
75
|
+
it = { expectation: 'of an existing file without inserting new bytes' };
|
|
76
|
+
it.func = async function (s) {
|
|
77
|
+
const { testFS } = s;
|
|
78
|
+
function expectSection(l, sectionInd, src, ofs, len) {
|
|
79
|
+
const section = l.sections[sectionInd];
|
|
80
|
+
if (section) {
|
|
81
|
+
expect(section.src).withContext(`source in section ${sectionInd}`).toBe(src);
|
|
82
|
+
expect(section.ofs).withContext(`offset in section ${sectionInd}`).toBe(ofs);
|
|
83
|
+
expect(section.len).withContext(`length in section ${sectionInd}`).toBe(len);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
fail(`section indexes ${sectionInd} is not in layout with ${l.sections.length} sections`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// setup original file
|
|
90
|
+
const fName = 'file1';
|
|
91
|
+
let sink = await testFS.getByteSink(fName, { create: true, exclusive: true });
|
|
92
|
+
const chunk1 = (0, random_node_1.bytesSync)(10000);
|
|
93
|
+
await sink.splice(0, chunk1.length, chunk1);
|
|
94
|
+
const chunk2 = (0, random_node_1.bytesSync)(100);
|
|
95
|
+
await sink.splice(11000, 0, chunk2);
|
|
96
|
+
await sink.done();
|
|
97
|
+
const initSize = await sink.getSize();
|
|
98
|
+
// sink for this test
|
|
99
|
+
sink = await testFS.getByteSink(fName, { create: false });
|
|
100
|
+
await sink.splice(5000, 4000);
|
|
101
|
+
let size = await sink.getSize();
|
|
102
|
+
expect(size).toBe(initSize - 4000);
|
|
103
|
+
let layout = await sink.showLayout();
|
|
104
|
+
if (testFS.type === 'device') {
|
|
105
|
+
expect(layout.sections.length).toBe(1);
|
|
106
|
+
expectSection(layout, 0, 'new', 0, size);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
expect(layout.sections.length).toBe(3);
|
|
110
|
+
expectSection(layout, 0, 'base', 0, 6000);
|
|
111
|
+
expectSection(layout, 1, 'empty', 6000, 1000);
|
|
112
|
+
expectSection(layout, 2, 'base', 7000, 100);
|
|
113
|
+
}
|
|
114
|
+
await sink.done();
|
|
115
|
+
const content = await testFS.readBytes(fName);
|
|
116
|
+
expect(content.length).toBe(size);
|
|
117
|
+
expect((0, bytes_equal_1.bytesEqual)(content.subarray(0, 5000), chunk1.subarray(0, 5000))).toBe(true);
|
|
118
|
+
expect((0, bytes_equal_1.bytesEqual)(content.subarray(5000, 6000), chunk1.subarray(9000))).toBe(true);
|
|
119
|
+
expect((0, bytes_equal_1.bytesEqual)(content.subarray(7000), chunk2)).toBe(true);
|
|
120
|
+
};
|
|
121
|
+
exports.specs.its.push(it);
|
|
122
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2020 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.specs = void 0;
|
|
20
|
+
const random_node_1 = require("../../../lib-common/random-node");
|
|
21
|
+
const bytes_equal_1 = require("../../libs-for-tests/bytes-equal");
|
|
22
|
+
exports.specs = {
|
|
23
|
+
description: 'gives file sinks, able to truncate file content',
|
|
24
|
+
its: []
|
|
25
|
+
};
|
|
26
|
+
let it = { expectation: 'of a newly created file' };
|
|
27
|
+
it.func = async function (s) {
|
|
28
|
+
const { testFS } = s;
|
|
29
|
+
function expectSection(l, sectionInd, src, ofs, len) {
|
|
30
|
+
const section = l.sections[sectionInd];
|
|
31
|
+
if (section) {
|
|
32
|
+
expect(section.src).withContext(`source in section ${sectionInd}`).toBe(src);
|
|
33
|
+
expect(section.ofs).withContext(`offset in section ${sectionInd}`).toBe(ofs);
|
|
34
|
+
expect(section.len).withContext(`length in section ${sectionInd}`).toBe(len);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
fail(`section index ${sectionInd} is not in layout with ${l.sections.length} sections`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const fName = 'file1';
|
|
41
|
+
const sink = await testFS.getByteSink(fName, { create: true, exclusive: true });
|
|
42
|
+
let size = await sink.getSize();
|
|
43
|
+
expect(size).toBe(0);
|
|
44
|
+
let layout = await sink.showLayout();
|
|
45
|
+
expect(Array.isArray(layout.sections)).toBeTruthy();
|
|
46
|
+
expect(layout.sections.length).toBe(0);
|
|
47
|
+
await sink.truncate(10000);
|
|
48
|
+
size = await sink.getSize();
|
|
49
|
+
expect(size).toBe(10000);
|
|
50
|
+
layout = await sink.showLayout();
|
|
51
|
+
expect(layout.sections.length).toBe(1);
|
|
52
|
+
if (testFS.type === 'device') {
|
|
53
|
+
expectSection(layout, 0, 'new', 0, 10000);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
expectSection(layout, 0, 'empty', 0, 10000);
|
|
57
|
+
}
|
|
58
|
+
const chunk = (0, random_node_1.bytesSync)(10000);
|
|
59
|
+
await sink.splice(0, chunk.length, chunk);
|
|
60
|
+
size = await sink.getSize();
|
|
61
|
+
expect(size).toBe(10000);
|
|
62
|
+
layout = await sink.showLayout();
|
|
63
|
+
expect(layout.sections.length).toBe(1);
|
|
64
|
+
expectSection(layout, 0, 'new', 0, size);
|
|
65
|
+
await sink.truncate(5000);
|
|
66
|
+
size = await sink.getSize();
|
|
67
|
+
expect(size).toBe(5000);
|
|
68
|
+
layout = await sink.showLayout();
|
|
69
|
+
expect(layout.sections.length).toBe(1);
|
|
70
|
+
expectSection(layout, 0, 'new', 0, size);
|
|
71
|
+
await sink.done();
|
|
72
|
+
const content = await testFS.readBytes(fName);
|
|
73
|
+
expect(content.length).toBe(size);
|
|
74
|
+
expect((0, bytes_equal_1.bytesEqual)(content, chunk.subarray(0, size))).toBe(true);
|
|
75
|
+
};
|
|
76
|
+
exports.specs.its.push(it);
|
|
77
|
+
it = {
|
|
78
|
+
expectation: 'and supports truncating without writing to file (scenario 1), checking version',
|
|
79
|
+
notIncludedIn: 'device-fs'
|
|
80
|
+
};
|
|
81
|
+
it.func = async function (s) {
|
|
82
|
+
const { testFS } = s;
|
|
83
|
+
async function checkSizeOf(file, expectedSize, expectedVersion) {
|
|
84
|
+
const { size, version } = await testFS.stat(file);
|
|
85
|
+
expect(size).withContext(`file size of "${file}"`).toBe(expectedSize);
|
|
86
|
+
expect(version).withContext(`file version`).toBe(expectedVersion);
|
|
87
|
+
}
|
|
88
|
+
const file = 'file to truncate';
|
|
89
|
+
let fileVersion = await testFS.v.writeTxtFile(file, '', { create: true, exclusive: true });
|
|
90
|
+
await checkSizeOf(file, 0, fileVersion);
|
|
91
|
+
let { sink, version } = await testFS.v.getByteSink(file, {});
|
|
92
|
+
await sink.truncate(500);
|
|
93
|
+
await sink.done();
|
|
94
|
+
await checkSizeOf(file, 500, version);
|
|
95
|
+
({ sink, version } = await testFS.v.getByteSink(file, {}));
|
|
96
|
+
await sink.truncate(100);
|
|
97
|
+
await sink.done();
|
|
98
|
+
await checkSizeOf(file, 100, version);
|
|
99
|
+
};
|
|
100
|
+
exports.specs.its.push(it);
|
|
101
|
+
it = {
|
|
102
|
+
expectation: 'and supports truncating without writing to file (scenario 1), without checking versions'
|
|
103
|
+
};
|
|
104
|
+
it.func = async function (s) {
|
|
105
|
+
const { testFS } = s;
|
|
106
|
+
async function checkSizeOf(file, expectedSize) {
|
|
107
|
+
const { size, version } = await testFS.stat(file);
|
|
108
|
+
expect(size).withContext(`file size of "${file}"`).toBe(expectedSize);
|
|
109
|
+
}
|
|
110
|
+
const file = 'file to truncate';
|
|
111
|
+
await testFS.writeTxtFile(file, '', { create: true, exclusive: true });
|
|
112
|
+
await checkSizeOf(file, 0);
|
|
113
|
+
let sink = await testFS.getByteSink(file, {});
|
|
114
|
+
await sink.truncate(500);
|
|
115
|
+
await sink.done();
|
|
116
|
+
await checkSizeOf(file, 500);
|
|
117
|
+
sink = await testFS.getByteSink(file, {});
|
|
118
|
+
await sink.truncate(100);
|
|
119
|
+
await sink.done();
|
|
120
|
+
await checkSizeOf(file, 100);
|
|
121
|
+
};
|
|
122
|
+
exports.specs.its.push(it);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2016, 2018, 2020 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.specs = void 0;
|
|
20
|
+
exports.specs = {
|
|
21
|
+
description: '.link, when linking from local into synced storage,',
|
|
22
|
+
its: []
|
|
23
|
+
};
|
|
24
|
+
let it = { expectation: 'links readonly file' };
|
|
25
|
+
it.func = async function (s) {
|
|
26
|
+
const { syncedTestFS, localTestFS } = s;
|
|
27
|
+
const original = 'Should I be at BlackHat conference or working?';
|
|
28
|
+
const fName = 'file1';
|
|
29
|
+
await syncedTestFS.writeTxtFile(fName, original);
|
|
30
|
+
let file = await syncedTestFS.readonlyFile(fName);
|
|
31
|
+
const linkPath = 'link1';
|
|
32
|
+
await localTestFS.link(linkPath, file);
|
|
33
|
+
const link = await localTestFS.readLink(linkPath);
|
|
34
|
+
expect(link.isFile).withContext('this link should be for a file').toBe(true);
|
|
35
|
+
expect(link.readonly).withContext('this link should be readonly').toBe(true);
|
|
36
|
+
file = (await link.target());
|
|
37
|
+
expect(!!file).withContext('target should be instantiated').toBe(true);
|
|
38
|
+
expect(await file.readTxt()).toBe(original);
|
|
39
|
+
expect(file.writable).toBe(false);
|
|
40
|
+
};
|
|
41
|
+
exports.specs.its.push(it);
|
|
42
|
+
it = { expectation: 'links writable file' };
|
|
43
|
+
it.func = async function (s) {
|
|
44
|
+
const { syncedTestFS, localTestFS } = s;
|
|
45
|
+
const original = 'Should I be at BlackHat conference or working?';
|
|
46
|
+
const fName = 'file1';
|
|
47
|
+
await syncedTestFS.writeTxtFile(fName, original);
|
|
48
|
+
let file = await syncedTestFS.writableFile(fName);
|
|
49
|
+
const linkPath = 'link1';
|
|
50
|
+
await localTestFS.link(linkPath, file);
|
|
51
|
+
const link = await localTestFS.readLink(linkPath);
|
|
52
|
+
expect(link.isFile).withContext('this link should be for a file').toBe(true);
|
|
53
|
+
expect(link.readonly).withContext('this link should be writable').toBe(false);
|
|
54
|
+
file = (await link.target());
|
|
55
|
+
expect(!!file).withContext('target should be instantiated').toBe(true);
|
|
56
|
+
expect(await file.readTxt()).toBe(original);
|
|
57
|
+
const newTxt = 'I better work. A-a-a!!!';
|
|
58
|
+
await file.writeTxt(newTxt);
|
|
59
|
+
expect(await file.readTxt()).toBe(newTxt);
|
|
60
|
+
};
|
|
61
|
+
exports.specs.its.push(it);
|
|
62
|
+
it = { expectation: 'links writable folder' };
|
|
63
|
+
it.func = async function (s) {
|
|
64
|
+
const { syncedTestFS, localTestFS } = s;
|
|
65
|
+
const original = 'Should I be at BlackHat conference or working?';
|
|
66
|
+
const folderName = 'folder1';
|
|
67
|
+
const fName = 'file1';
|
|
68
|
+
await syncedTestFS.writeTxtFile(`${folderName}/${fName}`, original);
|
|
69
|
+
let folder = await syncedTestFS.writableSubRoot(folderName);
|
|
70
|
+
const linkPath = 'link1';
|
|
71
|
+
await localTestFS.link(linkPath, folder);
|
|
72
|
+
const link = await localTestFS.readLink(linkPath);
|
|
73
|
+
expect(link.isFolder).withContext('this link should be for a folder').toBe(true);
|
|
74
|
+
expect(link.readonly).withContext('this link should be writable').toBe(false);
|
|
75
|
+
folder = (await link.target());
|
|
76
|
+
expect(!!folder).withContext('target should be instantiated').toBe(true);
|
|
77
|
+
expect(await folder.readTxtFile(fName)).toBe(original);
|
|
78
|
+
const newTxt = 'I better work. A-a-a!!!';
|
|
79
|
+
await folder.writeTxtFile(fName, newTxt);
|
|
80
|
+
expect(await folder.readTxtFile(fName)).toBe(newTxt);
|
|
81
|
+
};
|
|
82
|
+
exports.specs.its.push(it);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2016, 2018, 2020 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.specs = void 0;
|
|
20
|
+
exports.specs = {
|
|
21
|
+
description: '.link should fail to link from synced into local storage,',
|
|
22
|
+
its: []
|
|
23
|
+
};
|
|
24
|
+
let it = { expectation: 'linking file' };
|
|
25
|
+
it.func = async function (s) {
|
|
26
|
+
const { syncedTestFS, localTestFS } = s;
|
|
27
|
+
const original = 'Should I be at BlackHat conference or working?';
|
|
28
|
+
const fName = 'file1';
|
|
29
|
+
await localTestFS.writeTxtFile(fName, original);
|
|
30
|
+
const file = await localTestFS.readonlyFile(fName);
|
|
31
|
+
const linkPath = 'link1';
|
|
32
|
+
await syncedTestFS.link(linkPath, file).catch((err) => {
|
|
33
|
+
expect(typeof err).toBe('object');
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
exports.specs.its.push(it);
|
|
37
|
+
it = { expectation: 'linking folder' };
|
|
38
|
+
it.func = async function (s) {
|
|
39
|
+
const { syncedTestFS, localTestFS } = s;
|
|
40
|
+
const original = 'Should I be at BlackHat conference or working?';
|
|
41
|
+
const folderName = 'folder1';
|
|
42
|
+
const fName = 'file1';
|
|
43
|
+
await localTestFS.writeTxtFile(`${folderName}/${fName}`, original);
|
|
44
|
+
const folder = await localTestFS.writableSubRoot(folderName);
|
|
45
|
+
const linkPath = 'link1';
|
|
46
|
+
await syncedTestFS.link(linkPath, folder).catch((err) => {
|
|
47
|
+
expect(typeof err).toBe('object');
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
exports.specs.its.push(it);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2016, 2018, 2020, 2025 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.specs = void 0;
|
|
20
|
+
exports.specs = {
|
|
21
|
+
description: '.deleteFile',
|
|
22
|
+
its: []
|
|
23
|
+
};
|
|
24
|
+
let it = { expectation: 'cannot delete non-existing file' };
|
|
25
|
+
it.func = async function (s) {
|
|
26
|
+
const { testFS } = s;
|
|
27
|
+
const fName = 'non-existing-file';
|
|
28
|
+
expect(await testFS.checkFilePresence(fName)).toBe(false);
|
|
29
|
+
await testFS.deleteFile(fName)
|
|
30
|
+
.then(() => {
|
|
31
|
+
fail('deleting non-existing file must fail');
|
|
32
|
+
}, (exc) => {
|
|
33
|
+
expect(exc.notFound).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
await testFS.makeFolder(fName);
|
|
36
|
+
expect(await testFS.checkFolderPresence(fName)).toBe(true);
|
|
37
|
+
await testFS.deleteFile(fName)
|
|
38
|
+
.then(() => {
|
|
39
|
+
fail('deleting folder as file must fail');
|
|
40
|
+
}, (exc) => {
|
|
41
|
+
expect(exc.notFile || exc.opNotPermitted).withContext('folder is not a file').toBe(true);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
exports.specs.its.push(it);
|
|
45
|
+
it = { expectation: 'deletes file' };
|
|
46
|
+
it.func = async function (s) {
|
|
47
|
+
const { testFS } = s;
|
|
48
|
+
for (const fName of ['file1', 'folder/file1']) {
|
|
49
|
+
await testFS.writeTxtFile(fName, '');
|
|
50
|
+
expect(await testFS.checkFilePresence(fName)).toBe(true);
|
|
51
|
+
await testFS.deleteFile(fName);
|
|
52
|
+
expect(await testFS.checkFilePresence(fName)).toBe(false);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.specs.its.push(it);
|
|
56
|
+
it = { expectation: 'deletes files concurrently from fs objects that point to same node' };
|
|
57
|
+
it.func = async function (s) {
|
|
58
|
+
const { testFS } = s;
|
|
59
|
+
// folder objects should have the same underlying fs node
|
|
60
|
+
const folders = await Promise.all([1, 2, 3, 4, 5].map(() => testFS.writableSubRoot('folder')));
|
|
61
|
+
expect(folders.length).toBe(5);
|
|
62
|
+
const file1Name = 'file1';
|
|
63
|
+
await folders[0].writeTxtFile(file1Name, 'blah');
|
|
64
|
+
for (let i = 1; i < folders.length; i += 1) {
|
|
65
|
+
expect(await folders[i].checkFilePresence(file1Name)).toBeTrue();
|
|
66
|
+
}
|
|
67
|
+
await folders[0].deleteFile(file1Name);
|
|
68
|
+
for (let i = 1; i < folders.length; i += 1) {
|
|
69
|
+
expect(await folders[i].checkFilePresence(file1Name)).toBeFalse();
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
exports.specs.its.push(it);
|
|
73
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2016, 2020 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.specs = void 0;
|
|
20
|
+
exports.specs = {
|
|
21
|
+
description: '.deleteFile',
|
|
22
|
+
its: []
|
|
23
|
+
};
|
|
24
|
+
let it = { expectation: 'lists root' };
|
|
25
|
+
it.func = async function (s) {
|
|
26
|
+
const { testFS } = s;
|
|
27
|
+
const fName = 'non-existing-folder';
|
|
28
|
+
expect(await testFS.checkFolderPresence(fName)).toBe(false);
|
|
29
|
+
await testFS.deleteFolder(fName)
|
|
30
|
+
.then(() => {
|
|
31
|
+
fail('deleting non-existing folder must fail');
|
|
32
|
+
}, (exc) => {
|
|
33
|
+
expect(exc.notFound).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
await testFS.writeTxtFile(fName, '');
|
|
36
|
+
expect(await testFS.checkFilePresence(fName)).toBe(true);
|
|
37
|
+
await testFS.deleteFolder(fName)
|
|
38
|
+
.then(() => {
|
|
39
|
+
fail('deleting file as folder must fail');
|
|
40
|
+
}, (exc) => {
|
|
41
|
+
expect(exc.notDirectory || exc.notFound).withContext('folder is not a file').toBe(true);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
exports.specs.its.push(it);
|
|
45
|
+
it = { expectation: 'deletes folder' };
|
|
46
|
+
it.func = async function (s) {
|
|
47
|
+
const { testFS } = s;
|
|
48
|
+
for (const fName of ['folder1', 'parent/folder2']) {
|
|
49
|
+
await testFS.makeFolder(fName);
|
|
50
|
+
expect(await testFS.checkFolderPresence(fName)).toBe(true);
|
|
51
|
+
await testFS.deleteFolder(fName);
|
|
52
|
+
expect(await testFS.checkFolderPresence(fName)).toBe(false);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
exports.specs.its.push(it);
|
|
56
|
+
it = { expectation: 'will delete folder with content, only when flag is set' };
|
|
57
|
+
it.func = async function (s) {
|
|
58
|
+
const { testFS } = s;
|
|
59
|
+
const fName = 'folder';
|
|
60
|
+
await testFS.makeFolder(fName);
|
|
61
|
+
expect(await testFS.checkFolderPresence(fName)).toBe(true);
|
|
62
|
+
await testFS.writeTxtFile(fName + '/folder2/file1', '');
|
|
63
|
+
await testFS.writeTxtFile(fName + '/file2', '');
|
|
64
|
+
await testFS.deleteFolder(fName)
|
|
65
|
+
.then(() => {
|
|
66
|
+
fail('cannot remove folder with content, when flag is not set');
|
|
67
|
+
}, (exc) => {
|
|
68
|
+
expect(exc.notEmpty).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
expect(await testFS.checkFolderPresence(fName)).toBe(true);
|
|
71
|
+
await testFS.deleteFolder(fName, true);
|
|
72
|
+
expect(await testFS.checkFolderPresence(fName)).toBe(false);
|
|
73
|
+
};
|
|
74
|
+
exports.specs.its.push(it);
|
|
75
|
+
Object.freeze(exports);
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2016, 2018, 2020 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.specs = void 0;
|
|
20
|
+
const random_node_1 = require("../../../../lib-common/random-node");
|
|
21
|
+
const bytes_equal_1 = require("../../../libs-for-tests/bytes-equal");
|
|
22
|
+
const sink_utils_1 = require("../../../../lib-common/obj-streaming/sink-utils");
|
|
23
|
+
exports.specs = {
|
|
24
|
+
description: '.getByteSink',
|
|
25
|
+
its: []
|
|
26
|
+
};
|
|
27
|
+
let it = {
|
|
28
|
+
expectation: 'if not allowed to create, fails for missing file'
|
|
29
|
+
};
|
|
30
|
+
it.func = async function (s) {
|
|
31
|
+
const { testFS } = s;
|
|
32
|
+
await testFS.getByteSink('non-existing-file', {})
|
|
33
|
+
.then(() => {
|
|
34
|
+
fail('should fail for missing file');
|
|
35
|
+
}, (e) => {
|
|
36
|
+
expect(e.notFound).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
exports.specs.its.push(it);
|
|
40
|
+
it = { expectation: 'creates file in existing folder' };
|
|
41
|
+
it.func = async function (s) {
|
|
42
|
+
const { testFS } = s;
|
|
43
|
+
const path = 'file1';
|
|
44
|
+
const content = (0, random_node_1.bytesSync)(2 * 1024);
|
|
45
|
+
expect(await testFS.checkFilePresence(path)).toBe(false);
|
|
46
|
+
const sink = await testFS.getByteSink(path, { create: true });
|
|
47
|
+
expect(await testFS.checkFilePresence(path)).toBe(true);
|
|
48
|
+
expect(await sink.getSize()).toBe(0);
|
|
49
|
+
const continousSink = (0, sink_utils_1.makeContinuousSink)(sink);
|
|
50
|
+
for (let pointer = 0; pointer < content.length; pointer += 250) {
|
|
51
|
+
const chunkEnd = pointer + 250;
|
|
52
|
+
await continousSink(content.subarray(pointer, chunkEnd));
|
|
53
|
+
expect(await sink.getSize()).toBe(Math.min(chunkEnd, content.length));
|
|
54
|
+
}
|
|
55
|
+
expect(await sink.getSize()).toBe(content.length);
|
|
56
|
+
await continousSink(null);
|
|
57
|
+
const bytes = await testFS.readBytes(path);
|
|
58
|
+
expect(!!bytes).toBe(true);
|
|
59
|
+
expect((0, bytes_equal_1.bytesEqual)(content, bytes)).toBe(true);
|
|
60
|
+
};
|
|
61
|
+
exports.specs.its.push(it);
|
|
62
|
+
it = { expectation: 'creates parent folder(s) on the way' };
|
|
63
|
+
it.func = async function (s) {
|
|
64
|
+
const { testFS } = s;
|
|
65
|
+
const fName = 'file2';
|
|
66
|
+
const grParent = 'grand-parent';
|
|
67
|
+
const parent2 = 'grand-parent/parent2';
|
|
68
|
+
const path = `${parent2}/${fName}`;
|
|
69
|
+
expect(await testFS.checkFolderPresence(grParent)).toBe(false);
|
|
70
|
+
expect(await testFS.checkFolderPresence(parent2)).toBe(false);
|
|
71
|
+
expect(await testFS.checkFolderPresence(path)).toBe(false);
|
|
72
|
+
const sink = await testFS.getByteSink(path, { create: true });
|
|
73
|
+
expect(await testFS.checkFolderPresence(grParent)).toBe(true);
|
|
74
|
+
expect(await testFS.checkFolderPresence(parent2)).toBe(true);
|
|
75
|
+
expect(await testFS.checkFilePresence(path)).toBe(true);
|
|
76
|
+
// note that file existed before sink closing
|
|
77
|
+
await sink.done();
|
|
78
|
+
};
|
|
79
|
+
exports.specs.its.push(it);
|
|
80
|
+
it = { expectation: 'opens existing file' };
|
|
81
|
+
it.func = async function (s) {
|
|
82
|
+
const { testFS } = s;
|
|
83
|
+
const path = 'file2';
|
|
84
|
+
const bytes = (0, random_node_1.bytesSync)(2 * 1024);
|
|
85
|
+
const originalSize = bytes.length;
|
|
86
|
+
await testFS.writeBytes(path, bytes);
|
|
87
|
+
expect(await testFS.checkFilePresence(path)).toBe(true);
|
|
88
|
+
const sink = await testFS.getByteSink(path, { truncate: false });
|
|
89
|
+
expect(await sink.getSize()).withContext('Existing file should be opened as is').toBe(originalSize);
|
|
90
|
+
const continousSink = (0, sink_utils_1.makeContinuousSink)(sink, originalSize);
|
|
91
|
+
await continousSink(bytes);
|
|
92
|
+
expect(await sink.getSize()).toBe(originalSize + bytes.length);
|
|
93
|
+
await continousSink(null);
|
|
94
|
+
};
|
|
95
|
+
exports.specs.its.push(it);
|
|
96
|
+
Object.freeze(exports);
|