Skip to content

Commit

Permalink
Added GET method test for physical resources
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 13, 2017
1 parent bd3488b commit d40bba8
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test/tests/readPhysicalFile.js
Original file line number Diff line number Diff line change
@@ -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)
})
});
})
3 changes: 3 additions & 0 deletions test/tests/readPhysicalFile/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Hello!

This is the content of the file!

0 comments on commit d40bba8

Please sign in to comment.