Commit 1e590da8 authored by Julien Fontanet's avatar Julien Fontanet

feat: initial tests

parent 974972d7
.DS_Store .DS_Store
node_modules node_modules
test.js test.js
/test/config.toml
This diff is collapsed.
...@@ -31,9 +31,10 @@ ...@@ -31,9 +31,10 @@
"Samba" "Samba"
], ],
"scripts": { "scripts": {
"test": "eslint ./lib" "test": "tap ./test"
}, },
"devDependencies": { "devDependencies": {
"@iarna/toml": "^2.2.1",
"eslint": "^5.9.0", "eslint": "^5.9.0",
"eslint-config-prettier": "^3.3.0", "eslint-config-prettier": "^3.3.0",
"eslint-config-standard": "^12.0.0", "eslint-config-standard": "^12.0.0",
...@@ -41,7 +42,8 @@ ...@@ -41,7 +42,8 @@
"eslint-plugin-node": "^8.0.0", "eslint-plugin-node": "^8.0.0",
"eslint-plugin-promise": "^4.0.1", "eslint-plugin-promise": "^4.0.1",
"eslint-plugin-standard": "^4.0.0", "eslint-plugin-standard": "^4.0.0",
"prettier": "^1.15.3" "prettier": "^1.15.3",
"tap": "^12.1.0"
}, },
"license": "MIT" "license": "MIT"
} }
var fs = require('fs');
var path = require('path');
var t = require('tap');
var TOML = require('@iarna/toml');
var Smb2 = require('../');
function pFinally(promise, fn) {
return promise.then(fn, fn).then(function() {
return promise;
});
}
var dir = 'smb2-tests-' + Date.now();
var data = Buffer.from(
Array.from({ length: 1024 }, function() {
return Math.round(Math.random() * 255);
})
);
function mkdir(client) {
return client.mkdir(dir);
}
function writeFile(client) {
return client.writeFile(dir + '\\file.txt', data);
}
function readFile(client) {
return client.readFile(dir + '\\file.txt').then(function(result) {
t.same(result, data);
});
}
function unlink(client) {
return client.unlink(dir + '\\file.txt');
}
function rmdir(client) {
return client.rmdir(dir);
}
function main() {
var options = TOML.parse(
fs.readFileSync(path.join(__dirname, 'config.toml'))
);
options.autoCloseTimeout = 0;
var client = new Smb2(options);
return pFinally(
[mkdir, writeFile, readFile, unlink, rmdir].reduce(function(prev, fn) {
return prev.then(function(result) {
return t.test(fn.name, function() {
return fn(client, result);
});
});
}, Promise.resolve()),
function() {
return client.disconnect();
}
);
}
main().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