Commit c489d243 authored by Julien Fontanet's avatar Julien Fontanet

feat: initial tests

parent 8b931045
module.exports = {
extends: ['standard', 'prettier'],
globals: {
Promise: true,
},
parserOptions: {
ecmaVersion: 5,
},
rules: {
// detect incorrect import/require
'node/no-extraneous-import': 'error',
'node/no-extraneous-require': 'error',
'node/no-missing-require': 'error',
'node/no-missing-import': 'error',
},
extends: [
'standard',
'plugin:node/recommended',
'prettier',
'prettier/standard',
],
};
.DS_Store
node_modules
test.js
/test/config.toml
This diff is collapsed.
......@@ -31,9 +31,10 @@
"Samba"
],
"scripts": {
"test": "eslint ./lib"
"test": "tap ./test"
},
"devDependencies": {
"@iarna/toml": "^2.2.1",
"eslint": "^5.9.0",
"eslint-config-prettier": "^3.3.0",
"eslint-config-standard": "^12.0.0",
......@@ -43,7 +44,9 @@
"eslint-plugin-standard": "^4.0.0",
"husky": "^1.2.0",
"lint-staged": "^8.1.0",
"prettier": "^1.15.3"
"prettier": "^1.15.3",
"promise-toolbox": "^0.11.0",
"tap": "^12.1.0"
},
"license": "MIT",
"husky": {
......
const asyncFn = require('promise-toolbox/asyncFn');
const fs = require('fs');
const path = require('path');
const t = require('tap');
const TOML = require('@iarna/toml');
const Smb2 = require('../');
const dir = 'smb2-tests-' + Date.now();
const file = dir + '\\file.txt';
const data = Buffer.from(
Array.from({ length: 1024 }, function() {
return Math.round(Math.random() * 255);
})
);
const tests = {
mkdir: function(client) {
return client.mkdir(dir);
},
writeFile: function(client) {
return client.writeFile(file, data);
},
readFile: function(client) {
return client.readFile(file).then(function(result) {
t.same(result, data);
});
},
unlink: function(client) {
return client.unlink(file);
},
rmdir: function(client) {
return client.rmdir(dir);
},
};
asyncFn(function*() {
const options = TOML.parse(
fs.readFileSync(path.join(__dirname, 'config.toml'))
);
options.autoCloseTimeout = 0;
const client = new Smb2(options);
try {
let result;
for (const name of Object.keys(tests)) {
result = yield t.test(name, function() {
return tests[name](client, result);
});
}
} finally {
yield client.disconnect();
}
})().catch(t.threw);
# Copy this file as config.toml and configure
domain = 'WORKGROUP'
password = ''
share = '\\machine\share'
username = 'Administrator'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment