Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 9b05c1c

Browse files
authored
Merge pull request #536 from ldapjs/parallelize-tests
Refactor tests to be independent of each other
2 parents b13e50a + 6b514b9 commit 9b05c1c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+984
-1997
lines changed

lib/attribute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Attribute.prototype.addValue = function addValue(val) {
7171
if (Buffer.isBuffer(val)) {
7272
this._vals.push(val);
7373
} else {
74-
this._vals.push(new Buffer(val + '', _bufferEncoding(this.type)));
74+
this._vals.push(Buffer.from(val + '', _bufferEncoding(this.type)));
7575
}
7676
};
7777

lib/client/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright 2012 Mark Cavage, Inc. All rights reserved.
22

3-
var logger = Object.create(require('abstract-logging'));
4-
5-
var Client = require('./client');
3+
const logger = require('../logger');
4+
const Client = require('./client');
65

76

87

lib/controls/paged_results_control.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ PagedResultsControl.prototype.parse = function parse(buffer) {
4848
this._value.cookie = ber.readString(asn1.Ber.OctetString, true);
4949
//readString returns '' instead of a zero-length buffer
5050
if (!this._value.cookie)
51-
this._value.cookie = new Buffer(0);
51+
this._value.cookie = Buffer.alloc(0);
5252

5353
return true;
5454
}

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
22

3-
var logger = Object.create(require('abstract-logging'));
3+
var logger = require('./logger');
44

55
var client = require('./client');
66
var Attribute = require('./attribute');

lib/logger.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
const logger = Object.create(require('abstract-logging'))
4+
logger.child = function () { return logger }
5+
6+
module.exports = logger

lib/messages/del_request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ DeleteRequest.prototype._parse = function (ber, length) {
4444
DeleteRequest.prototype._toBer = function (ber) {
4545
assert.ok(ber);
4646

47-
var buf = new Buffer(this.entry.toString());
47+
var buf = Buffer.from(this.entry.toString());
4848
for (var i = 0; i < buf.length; i++)
4949
ber.writeByte(buf[i]);
5050

lib/messages/ext_request.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function ExtendedRequest(options) {
2828
if(Buffer.isBuffer(this.requestValue)) {
2929
this.requestValueBuffer = this.requestValue;
3030
} else {
31-
this.requestValueBuffer = new Buffer(this.requestValue || '', 'utf8');
31+
this.requestValueBuffer = Buffer.from(this.requestValue || '', 'utf8');
3232
}
3333
}
3434
util.inherits(ExtendedRequest, LDAPMessage);
@@ -58,7 +58,7 @@ Object.defineProperties(ExtendedRequest.prototype, {
5858
if(Buffer.isBuffer(val)) {
5959
this.requestValueBuffer = val;
6060
} else {
61-
this.requestValueBuffer = new Buffer(val, 'utf8');
61+
this.requestValueBuffer = Buffer.from(val, 'utf8');
6262
}
6363

6464
this.requestValue = val;

lib/messages/message.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var util = require('util');
55

66
var asn1 = require('asn1');
77

8+
var logger = require('../logger')
89
var Control = require('../controls').Control;
910
var Protocol = require('../protocol');
1011

@@ -32,7 +33,7 @@ function LDAPMessage(options) {
3233
this.protocolOp = options.protocolOp || undefined;
3334
this.controls = options.controls ? options.controls.slice(0) : [];
3435

35-
this.log = options.log;
36+
this.log = options.log || logger;
3637
}
3738
Object.defineProperties(LDAPMessage.prototype, {
3839
id: {

lib/messages/parser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var util = require('util');
66
var assert = require('assert-plus');
77
var asn1 = require('asn1');
88
var VError = require('verror').VError;
9+
var logger = require('../logger')
910

1011
var AbandonRequest = require('./abandon_request');
1112
var AddRequest = require('./add_request');
@@ -43,14 +44,13 @@ var BerReader = asn1.BerReader;
4344

4445
///--- API
4546

46-
function Parser(options) {
47+
function Parser(options = {}) {
4748
assert.object(options);
48-
assert.object(options.log);
4949

5050
EventEmitter.call(this);
5151

5252
this.buffer = null;
53-
this.log = options.log;
53+
this.log = options.log || logger;
5454
}
5555
util.inherits(Parser, EventEmitter);
5656

test/attribute.test.js

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,16 @@
1-
// Copyright 2011 Mark Cavage, Inc. All rights reserved.
2-
3-
var test = require('tap').test;
4-
5-
var asn1 = require('asn1');
6-
7-
8-
///--- Globals
9-
10-
var BerReader = asn1.BerReader;
11-
var BerWriter = asn1.BerWriter;
12-
var Attribute;
13-
14-
15-
///--- Tests
16-
17-
test('load library', function (t) {
18-
Attribute = require('../lib/index').Attribute;
19-
t.ok(Attribute);
20-
t.end();
21-
});
1+
'use strict';
222

3+
const { test } = require('tap');
4+
const { BerReader, BerWriter } = require('asn1');
5+
const { Attribute } = require('../lib');
236

247
test('new no args', function (t) {
258
t.ok(new Attribute());
269
t.end();
2710
});
2811

29-
3012
test('new with args', function (t) {
31-
var attr = new Attribute({
13+
const attr = new Attribute({
3214
type: 'cn',
3315
vals: ['foo', 'bar']
3416
});
@@ -43,24 +25,23 @@ test('new with args', function (t) {
4325
attr = new Attribute('not an object');
4426
});
4527
t.throws(function () {
46-
var typeThatIsNotAString = 1;
28+
const typeThatIsNotAString = 1;
4729
attr = new Attribute({
4830
type: typeThatIsNotAString
4931
});
5032
});
5133
t.end();
5234
});
5335

54-
5536
test('toBer', function (t) {
56-
var attr = new Attribute({
37+
const attr = new Attribute({
5738
type: 'cn',
5839
vals: ['foo', 'bar']
5940
});
6041
t.ok(attr);
61-
var ber = new BerWriter();
42+
const ber = new BerWriter();
6243
attr.toBer(ber);
63-
var reader = new BerReader(ber.buffer);
44+
const reader = new BerReader(ber.buffer);
6445
t.ok(reader.readSequence());
6546
t.equal(reader.readString(), 'cn');
6647
t.equal(reader.readSequence(), 0x31); // lber set
@@ -69,17 +50,16 @@ test('toBer', function (t) {
6950
t.end();
7051
});
7152

72-
7353
test('parse', function (t) {
74-
var ber = new BerWriter();
54+
const ber = new BerWriter();
7555
ber.startSequence();
7656
ber.writeString('cn');
7757
ber.startSequence(0x31);
7858
ber.writeStringArray(['foo', 'bar']);
7959
ber.endSequence();
8060
ber.endSequence();
8161

82-
var attr = new Attribute();
62+
const attr = new Attribute();
8363
t.ok(attr);
8464
t.ok(attr.parse(new BerReader(ber.buffer)));
8565

@@ -91,12 +71,12 @@ test('parse', function (t) {
9171
});
9272

9373
test('parse - without 0x31', function (t) {
94-
var ber = new BerWriter;
74+
const ber = new BerWriter;
9575
ber.startSequence();
9676
ber.writeString('sn');
9777
ber.endSequence();
9878

99-
var attr = new Attribute;
79+
const attr = new Attribute;
10080
t.ok(attr);
10181
t.ok(attr.parse(new BerReader(ber.buffer)));
10282

@@ -107,18 +87,18 @@ test('parse - without 0x31', function (t) {
10787
});
10888

10989
test('toString', function (t) {
110-
var attr = new Attribute({
90+
const attr = new Attribute({
11191
type: 'foobar',
11292
vals: ['asdf']
11393
});
114-
var expected = attr.toString();
115-
var actual = JSON.stringify(attr.json);
94+
const expected = attr.toString();
95+
const actual = JSON.stringify(attr.json);
11696
t.equal(actual, expected);
11797
t.end();
11898
});
11999

120100
test('isAttribute', function (t) {
121-
var isA = Attribute.isAttribute;
101+
const isA = Attribute.isAttribute;
122102
t.notOk(isA(null));
123103
t.notOk(isA('asdf'));
124104
t.ok(isA(new Attribute({
@@ -128,7 +108,7 @@ test('isAttribute', function (t) {
128108

129109
t.ok(isA({
130110
type: 'foo',
131-
vals: ['item', new Buffer(5)],
111+
vals: ['item', Buffer.alloc(5)],
132112
toBer: function () { /* placeholder */ }
133113
}));
134114

@@ -142,18 +122,17 @@ test('isAttribute', function (t) {
142122
t.end();
143123
});
144124

145-
146125
test('compare', function (t) {
147-
var comp = Attribute.compare;
148-
var a = new Attribute({
126+
const comp = Attribute.compare;
127+
const a = new Attribute({
149128
type: 'foo',
150129
vals: ['bar']
151130
});
152-
var b = new Attribute({
131+
const b = new Attribute({
153132
type: 'foo',
154133
vals: ['bar']
155134
});
156-
var notAnAttribute = 'this is not an attribute';
135+
const notAnAttribute = 'this is not an attribute';
157136

158137
t.throws(function () {
159138
comp(a, notAnAttribute);

0 commit comments

Comments
 (0)