Merge pull request #532 from ldapjs/back-to-tap

Convert tests back to node-tap
This commit is contained in:
James Sumners 2019-08-27 09:13:23 -04:00 committed by GitHub
commit 426c6a7d2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 183 additions and 133 deletions

77
.gitignore vendored
View File

@ -1,8 +1,77 @@
build
node_modules
coverage
*.log
*.ldif
*.tar.*
*.tgz
# Lock files
pnpm-lock.yaml
shrinkwrap.yaml
package-lock.json
yarn.lock
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
node_modules
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
# 0x
.__browserify_string_empty.js
profile-*
*.flamegraph
# tap --cov
.nyc_output/
# JetBrains IntelliJ IDEA
.idea/
*.iml
# VS Code
.vscode/
# xcode
build/*
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser
*.xcworkspace
xcuserdata
# macOS
.DS_Store
# keys
*.pem
*.env.json
*.env

1
.taprc Normal file
View File

@ -0,0 +1 @@
esm: false

View File

@ -33,20 +33,20 @@
"asn1": "0.2.3",
"assert-plus": "^1.0.0",
"backoff": "^2.5.0",
"ldap-filter": "^0.3.3",
"dashdash": "^1.14.0",
"ldap-filter": "^0.3.3",
"once": "^1.4.0",
"vasync": "^1.6.4",
"verror": "^1.8.1"
},
"devDependencies": {
"faucet": "0.0.1",
"istanbul": "^0.4.5",
"tape": "^4.6.2",
"tap": "^14.6.1",
"uuid": "^3.3.3"
},
"scripts": {
"report": "./node_modules/.bin/istanbul report html && open ./coverage/lcov-report/index.html",
"test": "./node_modules/.bin/istanbul cover --print none test/test.js | ./node_modules/.bin/faucet"
"test": "tap --no-cov 'test/**/*.test.js'",
"test:cov": "tap 'test/**/*.test.js'",
"test:cov:html": "tap --coverage-report=html 'test/**/*.test.js'",
"test:watch": "tap -n -w --no-coverage-report 'test/**/*.test.js'"
}
}

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -2,7 +2,7 @@
var logger = Object.create(require('abstract-logging'));
var test = require('tape').test;
var test = require('tap').test;
var uuid = require('uuid');
var vasync = require('vasync');
var util = require('util');
@ -642,10 +642,12 @@ test('search sizeLimit', function (t) {
res.on('error', t2.ifError.bind(t));
});
});
t.end()
});
test('search paged', function (t) {
test('search paged', {timeout: 10000}, function (t) {
t.test('paged - no pauses', function (t2) {
var countEntries = 0;
var countPages = 0;

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,5 +1,5 @@
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,4 +1,4 @@
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
///--- Globals

View File

@ -1,6 +1,6 @@
// Copyright 2015 Joyent, Inc.
var test = require('tape').test;
var test = require('tap').test;
var ldap = require('../lib/index');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var parse = require('../../lib/index').parseFilter;

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var uuid = require('uuid');
var ldap = require('../lib/index');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -3,7 +3,7 @@
var asn1 = require('asn1');
var logger = Object.create(require('abstract-logging'));
var test = require('tape').test;
var test = require('tap').test;
///--- Globals

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2014 Joyent, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var logger = Object.create(require('abstract-logging'));
///--- Globals

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;
var asn1 = require('asn1');

View File

@ -2,7 +2,8 @@
var logger = Object.create(require('abstract-logging'));
var test = require('tape').test;
var fs = require('fs')
var tap = require('tap');
var uuid = require('uuid');
var vasync = require('vasync');
@ -33,19 +34,27 @@ function getSock() {
///--- Tests
test('load library', function (t) {
tap.beforeEach(function (done, t) {
// We do not need a `.afterEach` to clean up the sock files because that
// is done when the server is destroyed.
t.context.sock = getSock()
done()
})
tap.test('load library', function (t) {
ldap = require('../lib/index');
t.ok(ldap.createServer);
t.end();
});
test('basic create', function (t) {
server = ldap.createServer();
tap.test('basic create', function (t) {
const server = ldap.createServer();
t.ok(server);
t.end();
});
test('properties', function (t) {
tap.test('properties', function (t) {
const server = ldap.createServer();
t.equal(server.name, 'LDAPServer');
// TODO: better test
@ -62,11 +71,10 @@ test('properties', function (t) {
});
});
test('listen on unix/named socket', function (t) {
tap.test('listen on unix/named socket', function (t) {
t.plan(2);
server = ldap.createServer();
sock = getSock();
server.listen(sock, function () {
const server = ldap.createServer();
server.listen(t.context.sock, function () {
t.ok(server.url);
t.equal(server.url.split(':')[0], 'ldapi');
server.close();
@ -74,9 +82,9 @@ test('listen on unix/named socket', function (t) {
});
});
test('listen on static port', function (t) {
tap.test('listen on static port', function (t) {
t.plan(2);
server = ldap.createServer();
const server = ldap.createServer();
server.listen(SERVER_PORT, '127.0.0.1', function () {
var addr = server.address();
t.equal(addr.port, parseInt(SERVER_PORT, 10));
@ -86,9 +94,9 @@ test('listen on static port', function (t) {
});
});
test('listen on ephemeral port', function (t) {
tap.test('listen on ephemeral port', function (t) {
t.plan(2);
server = ldap.createServer();
const server = ldap.createServer();
server.listen(0, 'localhost', function () {
var addr = server.address();
t.ok(addr.port > 0);
@ -98,7 +106,7 @@ test('listen on ephemeral port', function (t) {
});
});
test('route order', function (t) {
tap.test('route order', function (t) {
function generateHandler(response) {
var func = function handler(req, res, next) {
res.send({
@ -149,9 +157,8 @@ test('route order', function (t) {
});
});
test('route absent', function (t) {
server = ldap.createServer();
sock = getSock();
tap.test('route absent', function (t) {
const server = ldap.createServer();
var DN_ROUTE = 'dc=base';
var DN_MISSING = 'dc=absent';
@ -160,12 +167,12 @@ test('route absent', function (t) {
return next();
});
server.listen(sock, function () {
server.listen(t.context.sock, function () {
t.ok(true, 'server startup');
vasync.parallel({
'funcs': [
function presentBind(cb) {
var clt = ldap.createClient({ socketPath: sock });
var clt = ldap.createClient({ socketPath: t.context.sock });
clt.bind(DN_ROUTE, '', function (err) {
t.notOk(err);
clt.unbind();
@ -173,7 +180,7 @@ test('route absent', function (t) {
});
},
function absentBind(cb) {
var clt = ldap.createClient({ socketPath: sock });
var clt = ldap.createClient({ socketPath: t.context.sock });
clt.bind(DN_MISSING, '', function (err) {
t.ok(err);
t.equal(err.code, ldap.LDAP_NO_SUCH_OBJECT);
@ -190,10 +197,9 @@ test('route absent', function (t) {
});
});
test('route unbind', function (t) {
tap.test('route unbind', function (t) {
t.plan(4);
server = ldap.createServer();
sock = getSock();
const server = ldap.createServer();
server.unbind(function (req, res, next) {
t.ok(true, 'server unbind successful');
@ -201,9 +207,9 @@ test('route unbind', function (t) {
return next();
});
server.listen(sock, function () {
server.listen(t.context.sock, function () {
t.ok(true, 'server startup');
client = ldap.createClient({ socketPath: sock });
client = ldap.createClient({ socketPath: t.context.sock });
client.bind('', '', function (err) {
t.ifError(err, 'client bind error');
client.unbind(function (err) {
@ -215,16 +221,17 @@ test('route unbind', function (t) {
});
});
test('strict routing', function (t) {
tap.test('strict routing', function (t) {
var testDN = 'cn=valid';
var clt;
var server;
var sock = t.context.sock;
vasync.pipeline({
funcs: [
function setup(_, cb) {
server = ldap.createServer({
// strictDN: true - on by default
});
sock = getSock();
// invalid DNs would go to default handler
server.search('', function (req, res, next) {
t.ok(req.dn);
@ -279,11 +286,10 @@ test('strict routing', function (t) {
});
});
test('non-strict routing', function (t) {
server = ldap.createServer({
tap.test('non-strict routing', function (t) {
const server = ldap.createServer({
strictDN: false
});
sock = getSock();
var testDN = 'this ain\'t a DN';
// invalid DNs go to default handler
@ -295,10 +301,10 @@ test('non-strict routing', function (t) {
next();
});
server.listen(sock, function () {
server.listen(t.context.sock, function () {
t.ok(true, 'server startup');
var clt = ldap.createClient({
socketPath: sock,
socketPath: t.context.sock,
strictDN: false
});
clt.search(testDN, {scope: 'base'}, function (err, res) {
@ -310,17 +316,18 @@ test('non-strict routing', function (t) {
});
});
});
});
test('close accept a callback', function (t) {
server = ldap.createServer();
tap.test('close accept a callback', function (t) {
const server = ldap.createServer();
// callback is called when the server is closed
server.close(function(err){
t.end();
});
});
});
test('close without error calls callback', function (t) {
server = ldap.createServer();
tap.test('close without error calls callback', function (t) {
const server = ldap.createServer();
// when the server is closed without error, the callback parameter is undefined
server.listen(1389,'127.0.0.1',function(err){
server.close(function(err){
@ -328,14 +335,13 @@ test('non-strict routing', function (t) {
t.end();
});
});
});
});
test('close passes error to callback', function (t) {
server = ldap.createServer();
tap.test('close passes error to callback', function (t) {
const server = ldap.createServer();
// when the server is closed with an error, the error is the first parameter of the callback
server.close(function(err){
t.ok(err);
t.end();
});
});
});

View File

@ -1,28 +0,0 @@
// Copyright 2014 Mark Cavage. All rights reserved.
var assert = require('assert');
var fs = require('fs');
var path = require('path');
function runTests(directory) {
fs.readdir(directory, function (err, files) {
assert.ifError(err);
console.dir(files);
files.filter(function (f) {
return (/\.test\.js$/.test(f));
}).map(function (f) {
return (path.join(directory, f));
}).forEach(require);
});
}
///--- Run All Tests
(function main() {
runTests(__dirname);
runTests(path.join(__dirname, 'controls'));
runTests(path.join(__dirname, 'filters'));
runTests(path.join(__dirname, 'messages'));
})();

View File

@ -1,6 +1,6 @@
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
var test = require('tape').test;
var test = require('tap').test;