about summary refs log tree commit diff stats
path: root/js/blotbotboot/node_modules/irc/test/helpers.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/blotbotboot/node_modules/irc/test/helpers.js')
-rw-r--r--js/blotbotboot/node_modules/irc/test/helpers.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/js/blotbotboot/node_modules/irc/test/helpers.js b/js/blotbotboot/node_modules/irc/test/helpers.js
new file mode 100644
index 0000000..6051da6
--- /dev/null
+++ b/js/blotbotboot/node_modules/irc/test/helpers.js
@@ -0,0 +1,69 @@
+/* Mock irc server */
+
+var path = require('path');
+var fs = require('fs');
+var net = require('net');
+var tls = require('tls');
+var util = require('util');
+var EventEmitter = require('events').EventEmitter;
+
+var MockIrcd = function(port, encoding, isSecure) {
+    var self = this;
+    var connectionClass;
+    var options = {};
+
+    if (isSecure) {
+        connectionClass = tls;
+        options = {
+            key: fs.readFileSync(path.resolve(__dirname, 'data/ircd.key')),
+            cert: fs.readFileSync(path.resolve(__dirname, 'data/ircd.pem'))
+        };
+    } else {
+        connectionClass = net;
+    }
+
+    this.port = port || (isSecure ? 6697 : 6667);
+    this.encoding = encoding || 'utf-8';
+    this.incoming = [];
+    this.outgoing = [];
+
+    this.server = connectionClass.createServer(options, function(c) {
+        c.on('data', function(data) {
+            var msg = data.toString(self.encoding).split('\r\n').filter(function(m) { return m; });
+            self.incoming = self.incoming.concat(msg);
+        });
+
+        self.on('send', function(data) {
+            self.outgoing.push(data);
+            c.write(data);
+        });
+
+        c.on('end', function() {
+            self.emit('end');
+        });
+    });
+
+    this.server.listen(this.port);
+};
+util.inherits(MockIrcd, EventEmitter);
+
+MockIrcd.prototype.send = function(data) {
+    this.emit('send', data);
+};
+
+MockIrcd.prototype.close = function() {
+    this.server.close();
+};
+
+MockIrcd.prototype.getIncomingMsgs = function() {
+    return this.incoming;
+};
+
+var fixtures = require('./data/fixtures');
+module.exports.getFixtures = function(testSuite) {
+    return fixtures[testSuite];
+};
+
+module.exports.MockIrcd = function(port, encoding, isSecure) {
+    return new MockIrcd(port, encoding, isSecure);
+};