Skip to content

Commit

Permalink
Standarized the multiple tests in a single test file
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 13, 2017
1 parent d40bba8 commit 3cd3934
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 81 deletions.
20 changes: 20 additions & 0 deletions test/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ module.exports = (callback, options) => {
error(name + details)
callCallback();
}
callback.multiple = (nb, server) => {
var allGood = true;
var allMsg;
return function(good, msg)
{
--nb;
if(msg && allGood && !good)
allMsg = msg;
allGood = allGood && good;
if(nb === 0)
{
if(server)
server.stop(() => {
callback(allGood, allMsg);
})
else
callback(allGood, allMsg);
}
}
}
setTimeout(() => callback(false, 'Timeout'), options.timeout);
fn(callback)
}
Expand Down
10 changes: 2 additions & 8 deletions test/tests/listRootFolder.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
var webdav = require('../../lib/index.js'),
Client = require("webdav-fs")

module.exports = (test, options, index) => test('list root folder', _isValid =>
module.exports = (test, options, index) => test('list root folder', isValid =>
{
function isValid(good, msg)
{
server.stop(() => {
_isValid(good, msg);
})
}

var server = new webdav.WebDAVServer();
isValid = isValid.multiple(1, server);
server.rootResource.addChild(new webdav.VirtualFile('file.txt'), e => {
if(e)
{
Expand Down
20 changes: 2 additions & 18 deletions test/tests/makeFolder.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
var webdav = require('../../lib/index.js'),
Client = require("webdav-fs")

module.exports = (test, options, index) => test('make a folder', _isValid =>
module.exports = (test, options, index) => test('make a folder', isValid =>
{
var nb = 3;
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();
isValid = isValid.multiple(3, server);
server.rootResource.addChild(new webdav.VirtualFile('testFile.txt'), e => {
if(e)
{
Expand Down
20 changes: 2 additions & 18 deletions test/tests/readPhysicalFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,10 @@ var webdav = require('../../lib/index.js'),
path = require('path'),
fs = require('fs')

module.exports = (test, options, index) => test('read a physical file', _isValid =>
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();
isValid = isValid.multiple(2, server);
server.start(options.port + index);

var wfs = Client(
Expand Down
21 changes: 2 additions & 19 deletions test/tests/readVirtualFile.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
var webdav = require('../../lib/index.js'),
Client = require("webdav-fs")

module.exports = (test, options, index) => test('read a virtual file', _isValid =>
module.exports = (test, options, index) => test('read a virtual file', isValid =>
{
var nb;
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 files = {
'testFile1.txt': 'this is the content!',
'testFile2.txt': null,
'testFile3.txt': new Buffer([ 10, 12, 16, 100, 125, 200, 250 ]),
'testFile4.txt': true
}
nb = Object.keys(files).length + 1;

var server = new webdav.WebDAVServer();
server.start(options.port + index);
isValid = isValid.multiple(Object.keys(files).length + 1, server);

var wfs = Client(
"http://127.0.0.1:" + (options.port + index)
Expand Down
20 changes: 2 additions & 18 deletions test/tests/statVirtualFile.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,10 @@
var webdav = require('../../lib/index.js'),
Client = require("webdav-fs")

module.exports = (test, options, index) => test('stat of virtual file', _isValid =>
module.exports = (test, options, index) => test('stat of virtual 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();
isValid = isValid.multiple(2, server);
server.rootResource.addChild(new webdav.VirtualFile('testFile.txt'), e => {
if(e)
{
Expand Down

0 comments on commit 3cd3934

Please sign in to comment.