From f9ae5c12d82cc8f7eb0adecef5851e96f9178459 Mon Sep 17 00:00:00 2001 From: Martin Cizek Date: Thu, 17 Sep 2020 07:05:21 +0200 Subject: [PATCH] Add test --- lib/client/client.js | 4 +--- test/client.test.js | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/client/client.js b/lib/client/client.js index addc89a..720cec0 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -122,9 +122,7 @@ function Client (options) { }) } - this.servers = urls.map((host) => { - return url.parse(host) - }) + this.servers = urls.map(url.parse) } // select random server at the start diff --git a/test/client.test.js b/test/client.test.js index 51cf6af..2bfd228 100644 --- a/test/client.test.js +++ b/test/client.test.js @@ -340,7 +340,7 @@ tap.test('createClient', t => { t.throws(() => ldap.createClient(42), match) }) - t.test('url must be a string', async t => { + t.test('url must be a string or array', async t => { const match = /options\.url \(string\|array\) required/ t.throws(() => ldap.createClient({ url: {} }), match) t.throws(() => ldap.createClient({ url: 42 }), match) @@ -378,6 +378,29 @@ tap.test('createClient', t => { } }) + t.test('url array is correctly assigned', async t => { + getPort().then(function (unusedPortNumber) { + const client = ldap.createClient({ + url: [ + `ldap://0.0.0.0:${unusedPortNumber}`, + `ldap://0.0.0.1:${unusedPortNumber}` + ] + }) + + t.equal(client.servers.length, 2) + }) + }) + + t.test('url string is correctly parsed and assigned', async t => { + getPort().then(function (unusedPortNumber) { + const client = ldap.createClient({ + url: `ldap://0.0.0.0:${unusedPortNumber},0.0.0.1:${unusedPortNumber}` + }) + + t.equal(client.servers.length, 2) + }) + }) + // TODO: this test is really flaky. It would be better if we could validate // the options _withouth_ having to connect to a server. // t.test('attaches a child function to logger', async t => {