errors.test.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. 'use strict'
  2. const { test } = require('tap')
  3. const {
  4. LDAPError,
  5. ConnectionError,
  6. AbandonedError,
  7. TimeoutError,
  8. ConstraintViolationError,
  9. LDAP_OTHER
  10. } = require('../lib')
  11. test('basic error', function (t) {
  12. const msg = 'mymsg'
  13. const err = new LDAPError(msg, null, null)
  14. t.ok(err)
  15. t.equal(err.name, 'LDAPError')
  16. t.equal(err.code, LDAP_OTHER)
  17. t.equal(err.dn, '')
  18. t.equal(err.message, msg)
  19. t.end()
  20. })
  21. test('exports ConstraintViolationError', function (t) {
  22. const msg = 'mymsg'
  23. const err = new ConstraintViolationError(msg, null, null)
  24. t.ok(err)
  25. t.equal(err.name, 'ConstraintViolationError')
  26. t.equal(err.code, 19)
  27. t.equal(err.dn, '')
  28. t.equal(err.message, msg)
  29. t.end()
  30. })
  31. test('"custom" errors', function (t) {
  32. const errors = [
  33. { name: 'ConnectionError', Func: ConnectionError },
  34. { name: 'AbandonedError', Func: AbandonedError },
  35. { name: 'TimeoutError', Func: TimeoutError }
  36. ]
  37. errors.forEach(function (entry) {
  38. const msg = entry.name + 'msg'
  39. const err = new entry.Func(msg)
  40. t.ok(err)
  41. t.equal(err.name, entry.name)
  42. t.equal(err.code, LDAP_OTHER)
  43. t.equal(err.dn, '')
  44. t.equal(err.message, msg)
  45. })
  46. t.end()
  47. })