config-spec.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var chai = require('chai');
  2. var expect = chai.expect;
  3. var createConfig = require('../lib/config');
  4. describe('config', function () {
  5. it('use dstPort as localPort', function () {
  6. var config = {
  7. host: 'test.host', dstPort: 8000
  8. };
  9. expect(createConfig(config).localPort).to.be.equal(8000);
  10. });
  11. it('should emit an error', function () {
  12. var config = {
  13. host: 'remoteHost'
  14. };
  15. expect(createConfig.bind(null, config)).to.throw('dstPort not set');
  16. });
  17. it('throws an error if host is missing', function () {
  18. var config = {
  19. dstPort: 8000
  20. };
  21. expect(createConfig.bind(null, config)).to.throw('host not set');
  22. });
  23. });
  24. /*
  25. // Keep alive
  26. var configA = {
  27. host: '127.0.0.1',
  28. username: process.env.USER,
  29. dstPort: 8000,
  30. localPort: 7000,
  31. // Use keepAlive:true to keep the tunnel open.
  32. keepAlive: true
  33. };
  34. var tunnelKeepAlive = tunnel(configA, function() {
  35. console.log('Tunnel open');
  36. helper.createClient(7000, '127.0.0.1', console.log).on('close', function() {
  37. helper.createClient(7000, '127.0.0.1', console.log).on('close', function() {
  38. helper.createClient(7000, '127.0.0.1', console.log).on('close', function() {
  39. setTimeout(function() {
  40. // Call tunnel.close() to shutdown the server.
  41. console.log('TRYING TO CLOSE');
  42. tunnelKeepAlive.close();
  43. }, 2000);
  44. });
  45. });
  46. });
  47. }).on('error', function(e) {
  48. console.log('error', e);
  49. });
  50. });
  51. */