From aea18ee7c261ef853f27d5f60837f4b4154f2d86 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Wed, 31 May 2017 12:51:28 +0200 Subject: [PATCH] Added ResourceTester tests for the virtual and physical resources --- test/tests/resourceTesterPhysical.js | 93 +++++++++++++++++++ test/tests/resourceTesterPhysical/.gitkeep | 0 .../TEST-test_test Test%201 | 0 test/tests/resourceTesterPhysical/testFile1 | 0 test/tests/resourceTesterPhysical/testFile10 | 0 test/tests/resourceTesterPhysical/testFile11 | 0 test/tests/resourceTesterPhysical/testFile12 | 0 test/tests/resourceTesterPhysical/testFile13 | 0 test/tests/resourceTesterPhysical/testFile14 | 0 test/tests/resourceTesterPhysical/testFile15 | 0 test/tests/resourceTesterPhysical/testFile16 | 0 test/tests/resourceTesterPhysical/testFile17 | 0 test/tests/resourceTesterPhysical/testFile18 | 0 test/tests/resourceTesterPhysical/testFile19 | 0 test/tests/resourceTesterPhysical/testFile20 | 0 test/tests/resourceTesterPhysical/testFile21 | 0 test/tests/resourceTesterPhysical/testFile4 | 1 + test/tests/resourceTesterPhysical/testFile5 | 0 test/tests/resourceTesterPhysical/testFile6 | 1 + test/tests/resourceTesterPhysical/testFile7 | 0 test/tests/resourceTesterPhysical/testFile8 | 0 test/tests/resourceTesterPhysical/testFile9 | 0 test/tests/resourceTesterVirtual.js | 51 ++++++++++ 23 files changed, 146 insertions(+) create mode 100644 test/tests/resourceTesterPhysical.js create mode 100644 test/tests/resourceTesterPhysical/.gitkeep create mode 100644 test/tests/resourceTesterPhysical/TEST-test_test Test%201 create mode 100644 test/tests/resourceTesterPhysical/testFile1 create mode 100644 test/tests/resourceTesterPhysical/testFile10 create mode 100644 test/tests/resourceTesterPhysical/testFile11 create mode 100644 test/tests/resourceTesterPhysical/testFile12 create mode 100644 test/tests/resourceTesterPhysical/testFile13 create mode 100644 test/tests/resourceTesterPhysical/testFile14 create mode 100644 test/tests/resourceTesterPhysical/testFile15 create mode 100644 test/tests/resourceTesterPhysical/testFile16 create mode 100644 test/tests/resourceTesterPhysical/testFile17 create mode 100644 test/tests/resourceTesterPhysical/testFile18 create mode 100644 test/tests/resourceTesterPhysical/testFile19 create mode 100644 test/tests/resourceTesterPhysical/testFile20 create mode 100644 test/tests/resourceTesterPhysical/testFile21 create mode 100644 test/tests/resourceTesterPhysical/testFile4 create mode 100644 test/tests/resourceTesterPhysical/testFile5 create mode 100644 test/tests/resourceTesterPhysical/testFile6 create mode 100644 test/tests/resourceTesterPhysical/testFile7 create mode 100644 test/tests/resourceTesterPhysical/testFile8 create mode 100644 test/tests/resourceTesterPhysical/testFile9 create mode 100644 test/tests/resourceTesterVirtual.js diff --git a/test/tests/resourceTesterPhysical.js b/test/tests/resourceTesterPhysical.js new file mode 100644 index 00000000..883f1854 --- /dev/null +++ b/test/tests/resourceTesterPhysical.js @@ -0,0 +1,93 @@ +"use strict"; +var webdav = require('../../lib/index.js'), + path = require('path'), + fs = require('fs') + +function clearFolder(rootFolder) +{ + const files = fs.readdirSync(rootFolder); + for(let f of files) + { + if(f === '.gitkeep') + continue; + + f = path.join(rootFolder, f); + const s = fs.statSync(f); + if(s.isFile()) + fs.unlinkSync(f); + else + { + clearFolder(f); + fs.rmdirSync(f); + } + } +} + +module.exports = (test, options, index) => test('resource tester on the physical resources', (isValid, server) => +{ + isValid = isValid.multiple(2, server); + + const rootFolder = path.join(__dirname, 'resourceTesterPhysical'); + clearFolder(rootFolder); + + let fid = 0; + new webdav.ResourceTester({ + canHaveVirtualFolderChildren: false, + canHaveVirtualFileChildren: false, + canGetLastModifiedDate: true, + canGetCreationDate: true, + canRemoveChildren: false, + canHaveChildren: false, + canGetChildren: false, + canGetMimeType: true, + canBeCreated: true, + canBeDeleted: true, + canBeRenamed: true, + canGetSize: true, + canBeMoved: true, + canWrite: true, + canRead: true + }, + (willCreate, cb) => { + const name = path.join(rootFolder, 'testFile' + (++fid).toString()); + fs.writeFile(name, '', () => { + cb(new webdav.PhysicalFile(name)) + }) + } + ).run((results) => { + isValid(results.all.isValid, results.all.errors); + }) + + let fid2 = 0; + new webdav.ResourceTester({ + canHaveVirtualFolderChildren: true, + canHaveVirtualFileChildren: true, + canGetLastModifiedDate: true, + canGetCreationDate: true, + canRemoveChildren: true, + canHaveChildren: true, + canGetChildren: true, + canGetMimeType: false, + canBeCreated: true, + canBeDeleted: true, + canBeRenamed: true, + canGetSize: false, + canBeMoved: true, + canWrite: false, + canRead: false + }, + (willCreate, cb) => { + const name = path.join(rootFolder, 'testFolder' + (++fid2).toString()); + if(!willCreate) + { + fs.mkdir(name, () => { + cb(new webdav.PhysicalFolder(name)) + }) + } + else + cb(new webdav.PhysicalFolder(name)) + } + ).run((results) => { + isValid(results.all.isValid, results.all.errors); + }) +}) \ No newline at end of file diff --git a/test/tests/resourceTesterPhysical/.gitkeep b/test/tests/resourceTesterPhysical/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/TEST-test_test Test%201 b/test/tests/resourceTesterPhysical/TEST-test_test Test%201 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile1 b/test/tests/resourceTesterPhysical/testFile1 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile10 b/test/tests/resourceTesterPhysical/testFile10 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile11 b/test/tests/resourceTesterPhysical/testFile11 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile12 b/test/tests/resourceTesterPhysical/testFile12 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile13 b/test/tests/resourceTesterPhysical/testFile13 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile14 b/test/tests/resourceTesterPhysical/testFile14 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile15 b/test/tests/resourceTesterPhysical/testFile15 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile16 b/test/tests/resourceTesterPhysical/testFile16 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile17 b/test/tests/resourceTesterPhysical/testFile17 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile18 b/test/tests/resourceTesterPhysical/testFile18 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile19 b/test/tests/resourceTesterPhysical/testFile19 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile20 b/test/tests/resourceTesterPhysical/testFile20 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile21 b/test/tests/resourceTesterPhysical/testFile21 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile4 b/test/tests/resourceTesterPhysical/testFile4 new file mode 100644 index 00000000..01230bc2 --- /dev/null +++ b/test/tests/resourceTesterPhysical/testFile4 @@ -0,0 +1 @@ +content1content2 \ No newline at end of file diff --git a/test/tests/resourceTesterPhysical/testFile5 b/test/tests/resourceTesterPhysical/testFile5 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile6 b/test/tests/resourceTesterPhysical/testFile6 new file mode 100644 index 00000000..30d74d25 --- /dev/null +++ b/test/tests/resourceTesterPhysical/testFile6 @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/test/tests/resourceTesterPhysical/testFile7 b/test/tests/resourceTesterPhysical/testFile7 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile8 b/test/tests/resourceTesterPhysical/testFile8 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterPhysical/testFile9 b/test/tests/resourceTesterPhysical/testFile9 new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/resourceTesterVirtual.js b/test/tests/resourceTesterVirtual.js new file mode 100644 index 00000000..ae4f580e --- /dev/null +++ b/test/tests/resourceTesterVirtual.js @@ -0,0 +1,51 @@ +"use strict"; +var webdav = require('../../lib/index.js') + +module.exports = (test, options, index) => test('resource tester on the virtual resources', (isValid, server) => +{ + isValid = isValid.multiple(2, server); + + new webdav.ResourceTester({ + canHaveVirtualFolderChildren: false, + canHaveVirtualFileChildren: false, + canGetLastModifiedDate: true, + canGetCreationDate: true, + canRemoveChildren: false, + canHaveChildren: false, + canGetChildren: false, + canGetMimeType: true, + canBeCreated: true, + canBeDeleted: true, + canBeRenamed: true, + canGetSize: true, + canBeMoved: true, + canWrite: true, + canRead: true + }, + (willCreate, cb) => cb(new webdav.VirtualFile('test')) + ).run((results) => { + isValid(results.all.isValid, results.all.errors); + }) + + new webdav.ResourceTester({ + canHaveVirtualFolderChildren: true, + canHaveVirtualFileChildren: true, + canGetLastModifiedDate: true, + canGetCreationDate: true, + canRemoveChildren: true, + canHaveChildren: true, + canGetChildren: true, + canGetMimeType: false, + canBeCreated: true, + canBeDeleted: true, + canBeRenamed: true, + canGetSize: false, + canBeMoved: true, + canWrite: false, + canRead: false + }, + (willCreate, cb) => cb(new webdav.VirtualFolder('test')) + ).run((results) => { + isValid(results.all.isValid, results.all.errors); + }) +}) \ No newline at end of file