Skip to content

Commit

Permalink
Added more PROPFIND tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 15, 2017
1 parent 031794c commit a4c9e63
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 30 deletions.
54 changes: 54 additions & 0 deletions test/tests/statPhysical.js
Original file line number Diff line number Diff line change
@@ -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');
})
});
});
})
Empty file.
1 change: 1 addition & 0 deletions test/tests/statPhysical/testFolder/testFile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Content!!!
48 changes: 48 additions & 0 deletions test/tests/statVirtual.js
Original file line number Diff line number Diff line change
@@ -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);
})
});
});
})
30 changes: 0 additions & 30 deletions test/tests/statVirtualFile.js

This file was deleted.

0 comments on commit a4c9e63

Please sign in to comment.