create-server-test.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * create-server-test.js : namespace socket unit test for TLS.
  3. *
  4. * (C) 2011, Charlie Robbins, Paolo Fragomeni, & the Contributors.
  5. *
  6. */
  7. var assert = require('assert'),
  8. fs = require('fs'),
  9. net = require('net'),
  10. path = require('path'),
  11. tls = require('tls'),
  12. vows = require('vows'),
  13. nssocket = require('../lib/nssocket');
  14. function getBatch() {
  15. var args = Array.prototype.slice.call(arguments),
  16. res = {};
  17. return {
  18. "the createServer() method": {
  19. topic: function () {
  20. var outbound = new nssocket.NsSocket(),
  21. server = nssocket.createServer(this.callback.bind(null, null, outbound));
  22. server.listen.apply(server, args.concat(function () {
  23. outbound.connect.apply(outbound, args);
  24. }));
  25. },
  26. "should create a full-duplex namespaced socket": {
  27. topic: function (outbound, inbound) {
  28. outbound.on(['data', 'here', 'is'], this.callback.bind(outbound, null));
  29. inbound.send(['here', 'is'], 'something.');
  30. },
  31. "should handle namespaced events": function (_, data) {
  32. assert.isArray(this.event);
  33. assert.lengthOf(this.event, 3);
  34. assert.isString(this.event[0]);
  35. assert.isString(this.event[1]);
  36. assert.isString(this.event[2]);
  37. assert.isString(data);
  38. assert.equal(this.event[0], 'data');
  39. assert.equal(this.event[1], 'here');
  40. assert.equal(this.event[2], 'is');
  41. assert.equal(data, 'something.');
  42. }
  43. }
  44. }
  45. };
  46. }
  47. var PORT = 9564,
  48. HOST = "127.0.0.1",
  49. PIPE = path.join(__dirname, "fixtures", "nssocket.sock"),
  50. HOSTNAME = "localhost";
  51. vows.describe('nssocket/create-server').addBatch({
  52. "When using NsSocket": {
  53. "with `(PORT)` argument": getBatch(PORT),
  54. "with `(PORT, HOST)` arguments": getBatch(PORT + 1, HOST),
  55. "with `(PORT, HOSTNAME)` argument": getBatch(PORT + 2, HOSTNAME),
  56. "with `(PIPE)` argument": getBatch(PIPE)
  57. }
  58. }).addBatch({
  59. "When tests are finished": {
  60. "`PIPE` should be removed": function () {
  61. fs.unlinkSync(PIPE);
  62. }
  63. }
  64. }).export(module);