From b81f383ab2d08bac321e5e353aa3a5309a78d424 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Sat, 27 May 2017 12:20:41 +0200 Subject: [PATCH] Modified the '*.content = *' into '*.write(...) in the tests --- README.md | 59 ++++++++++++++++--------------- test/tests/persistence.js | 65 ++++++++++++++++++----------------- test/tests/readVirtualFile.js | 28 +++++++-------- test/tests/statVirtual.js | 31 +++++++++-------- 4 files changed, 94 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index 0c49bce2..9fa0707b 100644 --- a/README.md +++ b/README.md @@ -113,42 +113,45 @@ const server = new webdav.WebDAVServer({ // Create a virtual file var file = new webdav.VirtualFile('testFile.txt'); // Set the content of the virtual file -file.content = 'The content of the virtual file.'; - -// Add the virtual resources to the root folder -// Note that you can add resources even when the -// server is running -server.addResourceTree({ - r: new webdav.VirtualFolder('testFolder'), - c: [{ - r: new webdav.VirtualFolder('test1'), - c: new webdav.VirtualFile('test2') - }, { - r: new webdav.VirtualFolder('test2'), +file.write('The content of the virtual file.', false, (e) => { + if(e) + throw e; + + // Add the virtual resources to the root folder + // Note that you can add resources even when the + // server is running + server.addResourceTree({ + r: new webdav.VirtualFolder('testFolder'), c: [{ r: new webdav.VirtualFolder('test1'), c: new webdav.VirtualFile('test2') - },{ + }, { r: new webdav.VirtualFolder('test2'), - c: new webdav.VirtualFile('test2') + c: [{ + r: new webdav.VirtualFolder('test1'), + c: new webdav.VirtualFile('test2') + },{ + r: new webdav.VirtualFolder('test2'), + c: new webdav.VirtualFile('test2') + }] }] - }] -}, e => { - if(e) - throw e; - - // Start the server - server.start(httpServer => { - console.log('Server started with success on the port : ' + httpServer.address().port); + }, e => { + if(e) + throw e; + + // Start the server + server.start(httpServer => { + console.log('Server started with success on the port : ' + httpServer.address().port); - // [...] + // [...] - // Stop the server - server.stop(() => { - console.log('Server stopped with success!'); - }) + // Stop the server + server.stop(() => { + console.log('Server stopped with success!'); + }) + }); }); -}); +} ``` In this example, the resource tree will be the following : diff --git a/test/tests/persistence.js b/test/tests/persistence.js index c18f1c96..4911be4b 100644 --- a/test/tests/persistence.js +++ b/test/tests/persistence.js @@ -15,45 +15,46 @@ module.exports = (test, options, index) => test('persistence', (isValid, server) const server2 = new webdav.WebDAVServer(); const f1 = new webdav.VirtualFile('file1.txt'); const f1Content = 'ok, This content is the test'; - f1.content = f1Content; - server2.rootResource.addChild(f1, e => _(e, () => { - server2.rootResource.addChild(new webdav.VirtualFile('file2.txt'), e => _(e, () => { - const folder1 = new webdav.VirtualFolder('folder1'); - server2.rootResource.addChild(folder1, e => _(e, () => { - folder1.addChild(new webdav.VirtualFile('sfile1.txt'), e => _(e, () => { - folder1.addChild(new webdav.VirtualFile('sfile2.txt'), e => _(e, () => { - server2.save((e, o) => _(e, () => { - const json = JSON.stringify(o, null, 4); - const els = JSON.parse(json); + f1.write(f1Content, true, e => _(e, () => { + server2.rootResource.addChild(f1, e => _(e, () => { + server2.rootResource.addChild(new webdav.VirtualFile('file2.txt'), e => _(e, () => { + const folder1 = new webdav.VirtualFolder('folder1'); + server2.rootResource.addChild(folder1, e => _(e, () => { + folder1.addChild(new webdav.VirtualFile('sfile1.txt'), e => _(e, () => { + folder1.addChild(new webdav.VirtualFile('sfile2.txt'), e => _(e, () => { + server2.save((e, o) => _(e, () => { + const json = JSON.stringify(o, null, 4); + const els = JSON.parse(json); - server.load(els, [ - new webdav.PhysicalFSManager(), - new webdav.VirtualFSManager(), - new webdav.RootFSManager() - ], (e) => _(e, () => { - - var wfs = Client( - 'http://127.0.0.1:' + (options.port + index) - ); + server.load(els, [ + new webdav.PhysicalFSManager(), + new webdav.VirtualFSManager(), + new webdav.RootFSManager() + ], (e) => _(e, () => { + + var wfs = Client( + 'http://127.0.0.1:' + (options.port + index) + ); - wfs.stat('/file1.txt', (e) => _(e, () => { - wfs.stat('/file2.txt', (e) => _(e, () => { - wfs.stat('/folder1', (e) => _(e, () => { - wfs.stat('/folder1/sfile1.txt', (e) => _(e, () => { - wfs.stat('/folder1/sfile2.txt', (e) => _(e, () => { - wfs.readFile('/file1.txt', (e, content) => _(e, () => { - isValid(content === f1Content); + wfs.stat('/file1.txt', (e) => _(e, () => { + wfs.stat('/file2.txt', (e) => _(e, () => { + wfs.stat('/folder1', (e) => _(e, () => { + wfs.stat('/folder1/sfile1.txt', (e) => _(e, () => { + wfs.stat('/folder1/sfile2.txt', (e) => _(e, () => { + wfs.readFile('/file1.txt', (e, content) => _(e, () => { + isValid(content === f1Content); + })) })) - })) - })) - })) - })) - })) + })) + })) + })) + })) + })); })); })); })); })); })); })); - })); + })) }) \ No newline at end of file diff --git a/test/tests/readVirtualFile.js b/test/tests/readVirtualFile.js index 1c8ada4a..626d6095 100644 --- a/test/tests/readVirtualFile.js +++ b/test/tests/readVirtualFile.js @@ -10,6 +10,9 @@ module.exports = (test, options, index) => test('read a virtual file', (isValid, 'testFile3.txt': new Buffer([ 10, 12, 16, 100, 125, 200, 250 ]), 'testFile4.txt': true } + for(const fileName in files) + if(!files[fileName]) + files[fileName] = ''; isValid = isValid.multiple(Object.keys(files).length + 1, server); const _ = (e, cb) => { @@ -26,20 +29,17 @@ module.exports = (test, options, index) => test('read a virtual file', (isValid, for(const fileName in files) { const file = new webdav.VirtualFile(fileName); - file.content = files[fileName]; - - if(!files[fileName]) - files[fileName] = ''; - - server.rootResource.addChild(file, e => _(e, () => { - wfs.readFile('/' + fileName, (e, content) => { - if(e) - isValid(false, e) - else - isValid(content.toString() === files[fileName].toString(), 'Received : ' + content.toString() + ' but expected : ' + files[fileName].toString()); - }) - - })); + file.write(files[fileName].toString(), true, e => _(e, () => { + server.rootResource.addChild(file, e => _(e, () => { + wfs.readFile('/' + fileName, (e, content) => { + if(e) + isValid(false, e) + else + isValid(content.toString() === files[fileName].toString(), 'Received : ' + content.toString() + ' but expected : ' + files[fileName].toString()); + }) + + })); + })) } wfs.readFile('/fileNotFound.txt', (e, content) => { diff --git a/test/tests/statVirtual.js b/test/tests/statVirtual.js index db4a716c..8124880d 100644 --- a/test/tests/statVirtual.js +++ b/test/tests/statVirtual.js @@ -17,24 +17,25 @@ module.exports = (test, options, index) => test('stat of virtual resources', (is const folder = new webdav.VirtualFolder('testFolder'); server.rootResource.addChild(folder, e => _(e, () => { const file = new webdav.VirtualFile('testFile.txt'); - file.content = content; - folder.addChild(file, e => _(e, () => { + file.write(content, true, e => _(e, () => { + folder.addChild(file, e => _(e, () => { - var wfs = Client( - 'http://127.0.0.1:' + (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/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('/testFolder', (e, stat) => { + isValid(!e && stat.isDirectory(), 'Folder error'); + }) - wfs.stat('/notFoundFile.txt', (e, stat) => { - isValid(!!e); - }) - })); + wfs.stat('/notFoundFile.txt', (e, stat) => { + isValid(!!e); + }) + })); + })) })); }) \ No newline at end of file