From a4c9e633d4b79799b183db6d616e1cfb3825394e Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Mon, 15 May 2017 10:12:25 +0200 Subject: [PATCH] Added more PROPFIND tests --- test/tests/statPhysical.js | 54 +++++++++++++++++++ test/tests/statPhysical/.gitkeep | 0 .../statPhysical/testFolder/testFile.txt | 1 + test/tests/statVirtual.js | 48 +++++++++++++++++ test/tests/statVirtualFile.js | 30 ----------- 5 files changed, 103 insertions(+), 30 deletions(-) create mode 100644 test/tests/statPhysical.js create mode 100644 test/tests/statPhysical/.gitkeep create mode 100644 test/tests/statPhysical/testFolder/testFile.txt create mode 100644 test/tests/statVirtual.js delete mode 100644 test/tests/statVirtualFile.js diff --git a/test/tests/statPhysical.js b/test/tests/statPhysical.js new file mode 100644 index 00000000..ad9c37ef --- /dev/null +++ b/test/tests/statPhysical.js @@ -0,0 +1,54 @@ +var webdav = require('../../lib/index.js'), + Client = require('webdav-fs'), + path = require('path'), + fs = require('fs') + +module.exports = (test, options, index) => test('stat of physical resources', isValid => +{ + var server = new webdav.WebDAVServer(); + isValid = isValid.multiple(2, server); + + const content = 'Content!!!'; + + const folderName = 'testFolder'; + const folderPath = path.join(__dirname, 'statPhysical', folderName); + if(!fs.existsSync(folderPath)) + fs.mkdirSync(folderPath); + + const folder = new webdav.PhysicalFolder(folderPath); + server.rootResource.addChild(folder, e => { + if(e) + { + isValid(false, e) + return; + } + + const fileName = 'testFile.txt'; + const filePath = path.join(folderPath, fileName); + + if(!fs.existsSync(filePath)) + fs.writeFileSync(filePath, content); + + folder.addChild(new webdav.PhysicalFile(filePath), e => { + if(e) + { + isValid(false, e) + return; + } + + server.start(options.port + index); + + var wfs = Client( + "http://127.0.0.1:" + (options.port + index) + ); + + wfs.stat('/' + folderName + '/' + fileName, (e, stat) => { + isValid(!e && stat.name === fileName && stat.size === content.length && stat.isFile(), 'File error'); + }) + + wfs.stat('/' + folderName, (e, stat) => { + isValid(!e && stat.isDirectory(), 'Folder error'); + }) + }); + }); +}) \ No newline at end of file diff --git a/test/tests/statPhysical/.gitkeep b/test/tests/statPhysical/.gitkeep new file mode 100644 index 00000000..e69de29b diff --git a/test/tests/statPhysical/testFolder/testFile.txt b/test/tests/statPhysical/testFolder/testFile.txt new file mode 100644 index 00000000..056c1207 --- /dev/null +++ b/test/tests/statPhysical/testFolder/testFile.txt @@ -0,0 +1 @@ +Content!!! \ No newline at end of file diff --git a/test/tests/statVirtual.js b/test/tests/statVirtual.js new file mode 100644 index 00000000..03ac0bd8 --- /dev/null +++ b/test/tests/statVirtual.js @@ -0,0 +1,48 @@ +var webdav = require('../../lib/index.js'), + Client = require('webdav-fs'), + request = require('request') + +module.exports = (test, options, index) => test('stat of virtual resources', isValid => +{ + var server = new webdav.WebDAVServer(); + isValid = isValid.multiple(2, server); + + const content = 'Content!!!'; + + const folder = new webdav.VirtualFolder('testFolder'); + server.rootResource.addChild(folder, e => { + if(e) + { + isValid(false, e) + return; + } + + const file = new webdav.VirtualFile('testFile.txt'); + file.content = content; + folder.addChild(file, e => { + if(e) + { + isValid(false, e) + return; + } + + server.start(options.port + index); + + var wfs = Client( + "http://127.0.0.1:" + (options.port + index) + ); + + wfs.stat('/testFolder/testFile.txt', (e, stat) => { + isValid(!e && stat.name === 'testFile.txt' && stat.size === content.length && stat.isFile(), 'File error'); + }) + + wfs.stat('/testFolder', (e, stat) => { + isValid(!e && stat.isDirectory(), 'Folder error'); + }) + + wfs.stat('/notFoundFile.txt', (e, stat) => { + isValid(!!e); + }) + }); + }); +}) \ No newline at end of file diff --git a/test/tests/statVirtualFile.js b/test/tests/statVirtualFile.js deleted file mode 100644 index 3b184ae4..00000000 --- a/test/tests/statVirtualFile.js +++ /dev/null @@ -1,30 +0,0 @@ -var webdav = require('../../lib/index.js'), - Client = require('webdav-fs'), - request = require('request') - -module.exports = (test, options, index) => test('stat of virtual file', isValid => -{ - var server = new webdav.WebDAVServer(); - isValid = isValid.multiple(2, server); - server.rootResource.addChild(new webdav.VirtualFile('testFile.txt'), e => { - if(e) - { - isValid(false, e) - return; - } - - server.start(options.port + index); - - var wfs = Client( - "http://127.0.0.1:" + (options.port + index) - ); - - wfs.stat('/testFile.txt', (e, stat) => { - isValid(!e && stat.name === 'testFile.txt'); - }) - - wfs.stat('/notFoundFile.txt', (e, stat) => { - isValid(!!e); - }) - }); -}) \ No newline at end of file