You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.6 KiB

  1. /*
  2. * node-rdkafka - Node.js wrapper for RdKafka C/C++ library
  3. *
  4. * Copyright (c) 2016 Blizzard Entertainment
  5. *
  6. * This software may be modified and distributed under the terms
  7. * of the MIT license. See the LICENSE.txt file for details.
  8. */
  9. var addon = require('bindings')('node-librdkafka');
  10. var t = require('assert');
  11. var client;
  12. var defaultConfig = {
  13. 'client.id': 'kafka-mocha',
  14. 'group.id': 'kafka-mocha-grp',
  15. 'metadata.broker.list': 'localhost:9092'
  16. };
  17. module.exports = {
  18. 'Consumer': {
  19. 'afterEach': function() {
  20. client = null;
  21. },
  22. 'cannot be set without a topic config': function() {
  23. t.throws(function() {
  24. client = new addon.KafkaConsumer(defaultConfig);
  25. });
  26. },
  27. 'can be given a topic config': function() {
  28. client = new addon.KafkaConsumer(defaultConfig, {});
  29. },
  30. 'throws us an error if we provide an invalid configuration value': function() {
  31. t.throws(function() {
  32. client = new addon.KafkaConsumer({
  33. 'foo': 'bar'
  34. });
  35. }, 'should throw because the key is invalid1');
  36. },
  37. 'throws us an error if topic config is given something invalid': function() {
  38. t.throws(function() {
  39. client = new addon.KafkaConsumer(defaultConfig, { 'foo': 'bar' });
  40. });
  41. },
  42. 'ignores function arguments for global configuration': function() {
  43. client = new addon.KafkaConsumer({
  44. 'event_cb': function() {},
  45. 'group.id': 'mocha-test'
  46. }, {});
  47. t.ok(client);
  48. },
  49. 'ignores function arguments for topic configuration': function() {
  50. client = new addon.KafkaConsumer(defaultConfig, {
  51. 'partitioner_cb': function() {}
  52. });
  53. }
  54. },
  55. 'KafkaConsumer client': {
  56. 'beforeEach': function() {
  57. client = new addon.KafkaConsumer(defaultConfig, {});
  58. },
  59. 'afterEach': function() {
  60. client = null;
  61. },
  62. 'is an object': function() {
  63. t.equal(typeof(client), 'object');
  64. },
  65. 'requires configuration': function() {
  66. t.throws(function() {
  67. return new addon.KafkaConsumer();
  68. });
  69. },
  70. 'has necessary methods from superclass': function() {
  71. var methods = ['connect', 'disconnect', 'configureCallbacks', 'getMetadata'];
  72. methods.forEach(function(m) {
  73. t.equal(typeof(client[m]), 'function', 'Client is missing ' + m + ' method');
  74. });
  75. },
  76. 'has necessary bindings for librdkafka 1:1 binding': function() {
  77. var methods = ['assign', 'unassign', 'subscribe'];
  78. methods.forEach(function(m) {
  79. t.equal(typeof(client[m]), 'function', 'Client is missing ' + m + ' method');
  80. });
  81. }
  82. },
  83. };