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.

66 lines
1.9 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 consumerConfig = {
  12. 'group.id': 'awesome'
  13. };
  14. var producerConfig = {
  15. 'client.id': 'kafka-mocha',
  16. 'metadata.broker.list': 'localhost:9092',
  17. 'socket.timeout.ms': 250
  18. };
  19. var client;
  20. module.exports = {
  21. 'native addon': {
  22. 'exports something': function() {
  23. t.equal(typeof(addon), 'object');
  24. },
  25. 'exports valid producer': function() {
  26. t.equal(typeof(addon.Producer), 'function');
  27. t.throws(addon.Producer); // Requires constructor
  28. t.equal(typeof(new addon.Producer({}, {})), 'object');
  29. },
  30. 'exports valid consumer': function() {
  31. t.equal(typeof(addon.KafkaConsumer), 'function');
  32. t.throws(addon.KafkaConsumer); // Requires constructor
  33. t.equal(typeof(new addon.KafkaConsumer(consumerConfig, {})), 'object');
  34. },
  35. 'exports version': function() {
  36. t.ok(addon.librdkafkaVersion);
  37. },
  38. 'Producer client': {
  39. 'beforeEach': function() {
  40. client = new addon.Producer(producerConfig, {});
  41. },
  42. 'afterEach': function() {
  43. client = null;
  44. },
  45. 'is an object': function() {
  46. t.equal(typeof(client), 'object');
  47. },
  48. 'requires configuration': function() {
  49. t.throws(function() {
  50. return new addon.Producer();
  51. });
  52. },
  53. 'has necessary methods from superclass': function() {
  54. var methods = ['connect', 'disconnect', 'configureCallbacks', 'getMetadata'];
  55. methods.forEach(function(m) {
  56. t.equal(typeof(client[m]), 'function', 'Client is missing ' + m + ' method');
  57. });
  58. }
  59. }
  60. },
  61. };