From d40bba8c12e785a2778ed077011492ebd7d38791 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Sat, 13 May 2017 13:50:37 +0200 Subject: [PATCH] Added GET method test for physical resources --- test/tests/readPhysicalFile.js | 62 ++++++++++++++++++++++++++++ test/tests/readPhysicalFile/file.txt | 3 ++ 2 files changed, 65 insertions(+) create mode 100644 test/tests/readPhysicalFile.js create mode 100644 test/tests/readPhysicalFile/file.txt diff --git a/test/tests/readPhysicalFile.js b/test/tests/readPhysicalFile.js new file mode 100644 index 00000000..317d1d10 --- /dev/null +++ b/test/tests/readPhysicalFile.js @@ -0,0 +1,62 @@ +var webdav = require('../../lib/index.js'), + Client = require("webdav-fs"), + path = require('path'), + fs = require('fs') + +module.exports = (test, options, index) => test('read a physical file', _isValid => +{ + var nb = 2; + var allGood = true; + var allMsg; + function isValid(good, msg) + { + --nb; + if(msg && allGood && !good) + allMsg = msg; + allGood = allGood && good; + if(nb === 0) + { + server.stop(() => { + _isValid(allGood, allMsg); + }) + } + } + + var server = new webdav.WebDAVServer(); + server.start(options.port + index); + + var wfs = Client( + "http://127.0.0.1:" + (options.port + index) + ); + + const fileName = 'file.txt'; + const filePath = path.join(__dirname, 'readPhysicalFile', fileName); + server.rootResource.addChild(new webdav.PhysicalFile(filePath), e => { + if(e) + { + isValid(false, e) + return; + } + + wfs.readFile('/' + fileName, (e, content) => { + if(e) + isValid(false, e) + else + isValid(content.toString() === fs.readFileSync(filePath).toString()); + }) + }); + + const folderName = 'readPhysicalFile'; + const folderPath = path.join(__dirname, folderName); + server.rootResource.addChild(new webdav.PhysicalFolder(folderPath), e => { + if(e) + { + isValid(false, e) + return; + } + + wfs.readFile('/' + folderName, (e, content) => { + isValid(!!e) + }) + }); +}) \ No newline at end of file diff --git a/test/tests/readPhysicalFile/file.txt b/test/tests/readPhysicalFile/file.txt new file mode 100644 index 00000000..0d779bdb --- /dev/null +++ b/test/tests/readPhysicalFile/file.txt @@ -0,0 +1,3 @@ +Hello! + +This is the content of the file!