Skip to content

Commit

Permalink
Added ResourceTester tests for the virtual and physical resources
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed May 31, 2017
1 parent 36414fc commit aea18ee
Show file tree
Hide file tree
Showing 23 changed files with 146 additions and 0 deletions.
93 changes: 93 additions & 0 deletions test/tests/resourceTesterPhysical.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
"use strict";
var webdav = require('../../lib/index.js'),
path = require('path'),
fs = require('fs')

function clearFolder(rootFolder)
{
const files = fs.readdirSync(rootFolder);
for(let f of files)
{
if(f === '.gitkeep')
continue;

f = path.join(rootFolder, f);
const s = fs.statSync(f);
if(s.isFile())
fs.unlinkSync(f);
else
{
clearFolder(f);
fs.rmdirSync(f);
}
}
}

module.exports = (test, options, index) => test('resource tester on the physical resources', (isValid, server) =>
{
isValid = isValid.multiple(2, server);

const rootFolder = path.join(__dirname, 'resourceTesterPhysical');
clearFolder(rootFolder);

let fid = 0;
new webdav.ResourceTester({
canHaveVirtualFolderChildren: false,
canHaveVirtualFileChildren: false,
canGetLastModifiedDate: true,
canGetCreationDate: true,
canRemoveChildren: false,
canHaveChildren: false,
canGetChildren: false,
canGetMimeType: true,
canBeCreated: true,
canBeDeleted: true,
canBeRenamed: true,
canGetSize: true,
canBeMoved: true,
canWrite: true,
canRead: true
},
(willCreate, cb) => {
const name = path.join(rootFolder, 'testFile' + (++fid).toString());
fs.writeFile(name, '', () => {
cb(new webdav.PhysicalFile(name))
})
}
).run((results) => {
isValid(results.all.isValid, results.all.errors);
})

let fid2 = 0;
new webdav.ResourceTester({
canHaveVirtualFolderChildren: true,
canHaveVirtualFileChildren: true,
canGetLastModifiedDate: true,
canGetCreationDate: true,
canRemoveChildren: true,
canHaveChildren: true,
canGetChildren: true,
canGetMimeType: false,
canBeCreated: true,
canBeDeleted: true,
canBeRenamed: true,
canGetSize: false,
canBeMoved: true,
canWrite: false,
canRead: false
},
(willCreate, cb) => {
const name = path.join(rootFolder, 'testFolder' + (++fid2).toString());
if(!willCreate)
{
fs.mkdir(name, () => {
cb(new webdav.PhysicalFolder(name))
})
}
else
cb(new webdav.PhysicalFolder(name))
}
).run((results) => {
isValid(results.all.isValid, results.all.errors);
})
})
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
1 change: 1 addition & 0 deletions test/tests/resourceTesterPhysical/testFile4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
content1content2
Empty file.
1 change: 1 addition & 0 deletions test/tests/resourceTesterPhysical/testFile6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
Empty file.
Empty file.
Empty file.
51 changes: 51 additions & 0 deletions test/tests/resourceTesterVirtual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"use strict";
var webdav = require('../../lib/index.js')

module.exports = (test, options, index) => test('resource tester on the virtual resources', (isValid, server) =>
{
isValid = isValid.multiple(2, server);

new webdav.ResourceTester({
canHaveVirtualFolderChildren: false,
canHaveVirtualFileChildren: false,
canGetLastModifiedDate: true,
canGetCreationDate: true,
canRemoveChildren: false,
canHaveChildren: false,
canGetChildren: false,
canGetMimeType: true,
canBeCreated: true,
canBeDeleted: true,
canBeRenamed: true,
canGetSize: true,
canBeMoved: true,
canWrite: true,
canRead: true
},
(willCreate, cb) => cb(new webdav.VirtualFile('test'))
).run((results) => {
isValid(results.all.isValid, results.all.errors);
})

new webdav.ResourceTester({
canHaveVirtualFolderChildren: true,
canHaveVirtualFileChildren: true,
canGetLastModifiedDate: true,
canGetCreationDate: true,
canRemoveChildren: true,
canHaveChildren: true,
canGetChildren: true,
canGetMimeType: false,
canBeCreated: true,
canBeDeleted: true,
canBeRenamed: true,
canGetSize: false,
canBeMoved: true,
canWrite: false,
canRead: false
},
(willCreate, cb) => cb(new webdav.VirtualFolder('test'))
).run((results) => {
isValid(results.all.isValid, results.all.errors);
})
})

0 comments on commit aea18ee

Please sign in to comment.