Skip to content

Commit

Permalink
Merge pull request #302 from martynsmith/apeiron/fixtures
Browse files Browse the repository at this point in the history
Factor out test data into a fixtures file.
  • Loading branch information
jirwin committed Jan 13, 2015
2 parents 6c7e55c + 199a012 commit 71e09d3
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 121 deletions.
118 changes: 118 additions & 0 deletions test/data/fixtures.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
{
"basic": {
"sent": [
["NICK testbot", "Client sent NICK message"],
["USER nodebot 8 * :nodeJS IRC client", "Client sent USER message"],
["QUIT :node-irc says goodbye", "Client sent QUIT message"]
],

"received": [
[":localhost 001 testbot :Welcome to the Internet Relay Chat Network testbot\r\n", "Received welcome message"]
]
},
"parse-line": {
":irc.dollyfish.net.nz 372 nodebot :The message of the day was last changed: 2012-6-16 23:57": {
"prefix": "irc.dollyfish.net.nz",
"server": "irc.dollyfish.net.nz",
"command": "rpl_motd",
"rawCommand": "372",
"commandType": "reply",
"args": ["nodebot", "The message of the day was last changed: 2012-6-16 23:57"]
},
":Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test :Hello nodebot!": {
"prefix": "Ned!~martyn@irc.dollyfish.net.nz",
"nick": "Ned",
"user": "~martyn",
"host": "irc.dollyfish.net.nz",
"command": "PRIVMSG",
"rawCommand": "PRIVMSG",
"commandType": "normal",
"args": ["#test", "Hello nodebot!"]
},
":Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test ::-)": {
"prefix": "Ned!~martyn@irc.dollyfish.net.nz",
"nick": "Ned",
"user": "~martyn",
"host": "irc.dollyfish.net.nz",
"command": "PRIVMSG",
"rawCommand": "PRIVMSG",
"commandType": "normal",
"args": ["#test", ":-)"]
},
":Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test ::": {
"prefix": "Ned!~martyn@irc.dollyfish.net.nz",
"nick": "Ned",
"user": "~martyn",
"host": "irc.dollyfish.net.nz",
"command": "PRIVMSG",
"rawCommand": "PRIVMSG",
"commandType": "normal",
"args": ["#test", ":"]
},
":Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test ::^:^:": {
"prefix": "Ned!~martyn@irc.dollyfish.net.nz",
"nick": "Ned",
"user": "~martyn",
"host": "irc.dollyfish.net.nz",
"command": "PRIVMSG",
"rawCommand": "PRIVMSG",
"commandType": "normal",
"args": ["#test", ":^:^:"]
},
":some.irc.net 324 webuser #channel +Cnj 5:10": {
"prefix": "some.irc.net",
"server": "some.irc.net",
"command": "rpl_channelmodeis",
"rawCommand": "324",
"commandType": "reply",
"args": ["webuser", "#channel", "+Cnj", "5:10"]
},
":nick!user@host QUIT :Ping timeout: 252 seconds": {
"prefix": "nick!user@host",
"nick": "nick",
"user": "user",
"host": "host",
"command": "QUIT",
"rawCommand": "QUIT",
"commandType": "normal",
"args": ["Ping timeout: 252 seconds"]
},
":nick!user@host PRIVMSG #channel :so : colons: :are :: not a problem ::::": {
"prefix": "nick!user@host",
"nick": "nick",
"user": "user",
"host": "host",
"command": "PRIVMSG",
"rawCommand": "PRIVMSG",
"commandType": "normal",
"args": ["#channel", "so : colons: :are :: not a problem ::::"]
},
":pratchett.freenode.net 324 nodebot #ubuntu +CLcntjf 5:10 #ubuntu-unregged": {
"prefix": "pratchett.freenode.net",
"server": "pratchett.freenode.net",
"command": "rpl_channelmodeis",
"rawCommand": "324",
"commandType": "reply",
"args": ["nodebot", "#ubuntu", "+CLcntjf", "5:10", "#ubuntu-unregged"]
}

},
"433-before-001": {
"sent": [
["NICK testbot", "Client sent NICK message"],
["USER nodebot 8 * :nodeJS IRC client", "Client sent USER message"],
["NICK testbot1", "Client sent proper response to 433 nickname in use message"],
["QUIT :node-irc says goodbye", "Client sent QUIT message"]
],

"received": [
[":localhost 433 * testbot :Nickname is already in use.\r\n", "Received nick in use error"],
[":localhost 001 testbot1 :Welcome to the Internet Relay Chat Network testbot\r\n", "Received welcome message"]
],
"clientInfo": [
"hostmask is as expected after 433",
"nick is as expected after 433",
"maxLineLength is as expected after 433"
]
}
}
7 changes: 6 additions & 1 deletion test/mockircd.js → test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ MockIrcd.prototype.getIncomingMsgs = function() {
return this.incoming.filter(function(msg) { return msg; });
};

module.exports = function(port, encoding) {
var fixtures = require('./data/fixtures');
module.exports.getFixtures = function(testSuite) {
return fixtures[testSuite];
}

module.exports.MockIrcd = function(port, encoding) {
return new MockIrcd(port, encoding);
};
23 changes: 3 additions & 20 deletions test/test-433-before-001.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
var irc = require('../lib/irc');
var test = require('tape');

var MockIrcd = require('./mockircd');
var testHelpers = require('./helpers');

test('connect and sets hostmask when nick in use', function(t) {
var client, mock, expected;

mock = MockIrcd();
mock = testHelpers.MockIrcd();
client = new irc.Client('localhost', 'testbot', {debug: true});

expected = {
sent: [
['NICK testbot', 'Client sent NICK message'],
['USER nodebot 8 * :nodeJS IRC client', 'Client sent USER message'],
['NICK testbot1', 'Client sent proper response to 433 nickname in use message'],
['QUIT :node-irc says goodbye', 'Client sent QUIT message']
],

received: [
[':localhost 433 * testbot :Nickname is already in use.\r\n', 'Received nick in use error'],
[':localhost 001 testbot1 :Welcome to the Internet Relay Chat Network testbot\r\n', 'Received welcome message']
],
clientInfo: [
['hostmask is as expected after 433'],
['nick is as expected after 433'],
['maxLineLength is as expected after 433']
]
};
expected = testHelpers.getFixtures('433-before-001');

t.plan(expected.sent.length + expected.received.length + expected.clientInfo.length);

Expand Down
17 changes: 3 additions & 14 deletions test/test-irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,17 @@ var net = require('net');
var irc = require('../lib/irc');
var test = require('tape');

var MockIrcd = require('./mockircd');
var testHelpers = require('./helpers');

test('connect, register and quit', function(t) {
var client, mock, expected;

t.plan(3);

mock = MockIrcd();
mock = testHelpers.MockIrcd();
expected = testHelpers.getFixtures('basic');
client = new irc.Client('localhost', 'testbot', {});

expected = {
sent: [
['NICK testbot', 'Client sent NICK message'],
['USER nodebot 8 * :nodeJS IRC client', 'Client sent USER message'],
['QUIT :node-irc says goodbye', 'Client sent QUIT message']
],

received: [
[':localhost 001 testbot :Welcome to the Internet Relay Chat Network testbot\r\n', 'Received welcome message']
]
};

t.plan(expected.sent.length + expected.received.length);

mock.server.on('connection', function() {
Expand Down
89 changes: 3 additions & 86 deletions test/test-parse-line.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,10 @@
var parseMessage = require('../lib/parse_message');
var test = require('tape');

var testHelpers = require('./helpers');

test('irc.parseMessage', function(t) {
var checks = {
':irc.dollyfish.net.nz 372 nodebot :The message of the day was last changed: 2012-6-16 23:57': {
prefix: 'irc.dollyfish.net.nz',
server: 'irc.dollyfish.net.nz',
command: 'rpl_motd',
rawCommand: '372',
commandType: 'reply',
args: ['nodebot', 'The message of the day was last changed: 2012-6-16 23:57']
},
':Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test :Hello nodebot!': {
prefix: 'Ned!~martyn@irc.dollyfish.net.nz',
nick: 'Ned',
user: '~martyn',
host: 'irc.dollyfish.net.nz',
command: 'PRIVMSG',
rawCommand: 'PRIVMSG',
commandType: 'normal',
args: ['#test', 'Hello nodebot!']
},
':Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test ::-)': {
prefix: 'Ned!~martyn@irc.dollyfish.net.nz',
nick: 'Ned',
user: '~martyn',
host: 'irc.dollyfish.net.nz',
command: 'PRIVMSG',
rawCommand: 'PRIVMSG',
commandType: 'normal',
args: ['#test', ':-)']
},
':Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test ::': {
prefix: 'Ned!~martyn@irc.dollyfish.net.nz',
nick: 'Ned',
user: '~martyn',
host: 'irc.dollyfish.net.nz',
command: 'PRIVMSG',
rawCommand: 'PRIVMSG',
commandType: 'normal',
args: ['#test', ':']
},
':Ned!~martyn@irc.dollyfish.net.nz PRIVMSG #test ::^:^:': {
prefix: 'Ned!~martyn@irc.dollyfish.net.nz',
nick: 'Ned',
user: '~martyn',
host: 'irc.dollyfish.net.nz',
command: 'PRIVMSG',
rawCommand: 'PRIVMSG',
commandType: 'normal',
args: ['#test', ':^:^:']
},
':some.irc.net 324 webuser #channel +Cnj 5:10': {
prefix: 'some.irc.net',
server: 'some.irc.net',
command: 'rpl_channelmodeis',
rawCommand: '324',
commandType: 'reply',
args: ['webuser', '#channel', '+Cnj', '5:10']
},
':nick!user@host QUIT :Ping timeout: 252 seconds': {
prefix: 'nick!user@host',
nick: 'nick',
user: 'user',
host: 'host',
command: 'QUIT',
rawCommand: 'QUIT',
commandType: 'normal',
args: ['Ping timeout: 252 seconds']
},
':nick!user@host PRIVMSG #channel :so : colons: :are :: not a problem ::::': {
prefix: 'nick!user@host',
nick: 'nick',
user: 'user',
host: 'host',
command: 'PRIVMSG',
rawCommand: 'PRIVMSG',
commandType: 'normal',
args: ['#channel', 'so : colons: :are :: not a problem ::::']
},
':pratchett.freenode.net 324 nodebot #ubuntu +CLcntjf 5:10 #ubuntu-unregged': {
prefix: 'pratchett.freenode.net',
server: 'pratchett.freenode.net',
command: 'rpl_channelmodeis',
rawCommand: '324',
commandType: 'reply',
args: ['nodebot', '#ubuntu', '+CLcntjf', '5:10', '#ubuntu-unregged']
}
};
var checks = testHelpers.getFixtures('parse-line');

Object.keys(checks).forEach(function(line) {
t.equal(
Expand Down

0 comments on commit 71e09d3

Please sign in to comment.