@@ -331,6 +331,64 @@ tap.afterEach((done, t) => {
331
331
} )
332
332
} )
333
333
334
+ tap . test ( 'createClient' , t => {
335
+ t . test ( 'requires an options object' , async t => {
336
+ const match = / o p t i o n s .+ r e q u i r e d /
337
+ t . throws ( ( ) => ldap . createClient ( ) , match )
338
+ t . throws ( ( ) => ldap . createClient ( [ ] ) , match )
339
+ t . throws ( ( ) => ldap . createClient ( '' ) , match )
340
+ t . throws ( ( ) => ldap . createClient ( 42 ) , match )
341
+ } )
342
+
343
+ t . test ( 'url must be a string' , async t => {
344
+ const match = / o p t i o n s \. u r l \( s t r i n g \) r e q u i r e d /
345
+ t . throws ( ( ) => ldap . createClient ( { url : { } } ) , match )
346
+ t . throws ( ( ) => ldap . createClient ( { url : [ ] } ) , match )
347
+ t . throws ( ( ) => ldap . createClient ( { url : 42 } ) , match )
348
+ } )
349
+
350
+ t . test ( 'socketPath must be a string' , async t => {
351
+ const match = / o p t i o n s \. s o c k e t P a t h m u s t b e a s t r i n g /
352
+ t . throws ( ( ) => ldap . createClient ( { socketPath : { } } ) , match )
353
+ t . throws ( ( ) => ldap . createClient ( { socketPath : [ ] } ) , match )
354
+ t . throws ( ( ) => ldap . createClient ( { socketPath : 42 } ) , match )
355
+ } )
356
+
357
+ t . test ( 'cannot supply both url and socketPath' , async t => {
358
+ t . throws (
359
+ ( ) => ldap . createClient ( { url : 'foo' , socketPath : 'bar' } ) ,
360
+ / o p t i o n s \. u r l \^ o p t i o n s \. s o c k e t P a t h \( S t r i n g \) r e q u i r e d /
361
+ )
362
+ } )
363
+
364
+ t . test ( 'must supply at least url or socketPath' , async t => {
365
+ t . throws (
366
+ ( ) => ldap . createClient ( { } ) ,
367
+ / o p t i o n s \. u r l \^ o p t i o n s \. s o c k e t P a t h \( S t r i n g \) r e q u i r e d /
368
+ )
369
+ } )
370
+
371
+ // TODO: this test is really flaky. It would be better if we could validate
372
+ // the options _withouth_ having to connect to a server.
373
+ // t.test('attaches a child function to logger', async t => {
374
+ // /* eslint-disable-next-line */
375
+ // let client
376
+ // const logger = Object.create(require('abstract-logging'))
377
+ // const socketPath = getSock()
378
+ // const server = ldap.createServer()
379
+ // server.listen(socketPath, () => {})
380
+ // t.tearDown(() => {
381
+ // client.unbind(() => server.close())
382
+ // })
383
+
384
+ // client = ldap.createClient({ socketPath, log: logger })
385
+ // t.ok(logger.child)
386
+ // t.true(typeof client.log.child === 'function')
387
+ // })
388
+
389
+ t . end ( )
390
+ } )
391
+
334
392
tap . test ( 'simple bind failure' , function ( t ) {
335
393
t . context . client . bind ( BIND_DN , uuid ( ) , function ( err , res ) {
336
394
t . ok ( err )
0 commit comments