This commit is contained in:
Martin Cizek 2020-09-17 07:05:21 +02:00
parent 3ca2c265da
commit f9ae5c12d8
2 changed files with 25 additions and 4 deletions

View File

@ -122,9 +122,7 @@ function Client (options) {
}) })
} }
this.servers = urls.map((host) => { this.servers = urls.map(url.parse)
return url.parse(host)
})
} }
// select random server at the start // select random server at the start

View File

@ -340,7 +340,7 @@ tap.test('createClient', t => {
t.throws(() => ldap.createClient(42), match) 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/ const match = /options\.url \(string\|array\) required/
t.throws(() => ldap.createClient({ url: {} }), match) t.throws(() => ldap.createClient({ url: {} }), match)
t.throws(() => ldap.createClient({ url: 42 }), 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 // TODO: this test is really flaky. It would be better if we could validate
// the options _withouth_ having to connect to a server. // the options _withouth_ having to connect to a server.
// t.test('attaches a child function to logger', async t => { // t.test('attaches a child function to logger', async t => {