make testing quieter, match expectations
This commit is contained in:
parent
b00c7c10d7
commit
aa777a6ab6
|
@ -3,13 +3,13 @@ socket = require "socket"
|
|||
test = require "ketracel.test"
|
||||
Server = require("ketracel.server").Server
|
||||
uuid = require "uuid"
|
||||
ln = require "ln"
|
||||
|
||||
describe "ngircd protocol support", ->
|
||||
local server
|
||||
local client
|
||||
|
||||
setup ->
|
||||
print "got here"
|
||||
file = io.popen "ngircd -n -f ./spec/ngircd.conf", "r"
|
||||
server = Server
|
||||
server: "127.0.0.1"
|
||||
|
@ -17,7 +17,7 @@ describe "ngircd protocol support", ->
|
|||
spass: "hunter2"
|
||||
sreal: "Ketracel"
|
||||
nicklen: "31"
|
||||
debug: true
|
||||
debug: os.getenv "DEBUG"
|
||||
client = test.Client "test_user"
|
||||
|
||||
teardown ->
|
||||
|
@ -29,15 +29,59 @@ describe "ngircd protocol support", ->
|
|||
data = \read "*all"
|
||||
assert.truthy string.find data, "ngircd"
|
||||
|
||||
it "registers", ->
|
||||
server\wait_for "376"
|
||||
it "sees end of burst", ->
|
||||
server\wait_for "376"
|
||||
|
||||
it "can use the Client class", ->
|
||||
client\wait_for "005"
|
||||
|
||||
it "sees the client", ->
|
||||
server\wait_for "NICK"
|
||||
server\wait_for "NICK", (source, user) ->
|
||||
user.nick == "test_user"
|
||||
|
||||
local channame
|
||||
|
||||
it "sees the client join a new channel", ->
|
||||
client.irc\JOIN "#" .. uuid()
|
||||
server\wait_for "JOIN"
|
||||
channame = uuid()
|
||||
client.irc\JOIN "#" .. channame
|
||||
server\wait_for "JOIN", (who, chan) ->
|
||||
chan.name == "#" .. channame
|
||||
client\wait_for "JOIN", (sender, channel) ->
|
||||
channel\sub(2) == channame
|
||||
|
||||
it "sees the client part the channel", ->
|
||||
client.irc\PART "#" .. channame
|
||||
server\wait_for "PART", (who, chan) ->
|
||||
chan.name == "#" .. channame
|
||||
|
||||
it "sees nickchanges", ->
|
||||
client.irc\send_raw "NICK newnick"
|
||||
server\wait_for "NICKCHG", (sender, clinfo) ->
|
||||
clinfo.nick == "newnick"
|
||||
|
||||
it "sees quits", ->
|
||||
cli = test.Client "quitter"
|
||||
cli\wait_for "005"
|
||||
cli.irc\QUIT "bye"
|
||||
server\wait_for "QUIT", (sender, msg) ->
|
||||
sender == "quitter"
|
||||
|
||||
it "sees a privmsg", ->
|
||||
client.irc\JOIN "#ketracel"
|
||||
client.irc\PRIVMSG "#ketracel", "hi"
|
||||
server\wait_for "PRIVMSG", (sender, params) ->
|
||||
params[1] == "#ketracel" and params[2] == "hi"
|
||||
|
||||
describe "ketracel bot", ->
|
||||
it "has a working VHOST command", ->
|
||||
client.irc\PRIVMSG "Ketracel", "VHOST my.cool.vhost"
|
||||
server\wait_for "PRIVMSG", (sender, params) ->
|
||||
params[1] == "Ketracel" and params[2] == "VHOST my.cool.vhost"
|
||||
client\wait_for "396"
|
||||
client\wait_for "NOTICE", (sender, origin, message, pm) ->
|
||||
message\find "my.cool.vhost"
|
||||
|
||||
it "replies to unknown commands", ->
|
||||
client.irc\PRIVMSG "KETRACEL", uuid()
|
||||
server\wait_for "PRIVMSG"
|
||||
client\wait_for "NOTICE"
|
||||
|
|
|
@ -2,6 +2,7 @@ irce = require "irce"
|
|||
util = require "irce.util"
|
||||
stringx = require "pl.stringx"
|
||||
moon = require "moon"
|
||||
ln = require "ln"
|
||||
|
||||
{
|
||||
init: (state) =>
|
||||
|
@ -99,15 +100,18 @@ moon = require "moon"
|
|||
state.channels[chan] = {name: chan, mode: "", members: {}, topic: ""}
|
||||
state.channels[chan].members[nick] = mode
|
||||
|
||||
state.channels[chan]
|
||||
sender[1], state.channels[chan]
|
||||
|
||||
["PART"]: (state, sender, params) =>
|
||||
chan = params[1]
|
||||
nick = string.lower sender[1]
|
||||
cinfo = state.channels[chan]
|
||||
state.channels[chan].members[nick] = nil
|
||||
if #state.channels[chan].members == 0
|
||||
state.channels[chan] = nil
|
||||
|
||||
sender[1], cinfo
|
||||
|
||||
["QUIT"]: (state, sender, params) =>
|
||||
nick = string.lower sender[1]
|
||||
state.clients[nick] = nil
|
||||
|
@ -115,6 +119,8 @@ moon = require "moon"
|
|||
for k, v in pairs state.channels
|
||||
v.members[nick] = nil
|
||||
|
||||
sender[1], params[1]
|
||||
|
||||
["NICK"]: (state, sender, params) =>
|
||||
if #params == 1
|
||||
oldnick = sender[1]
|
||||
|
@ -132,7 +138,8 @@ moon = require "moon"
|
|||
v.members[nick] = v.members[oldnicksmall]
|
||||
v.members[oldnicksmall] = nil
|
||||
|
||||
return sender, state.clients[nick]
|
||||
@handle "NICKCHG", sender, state.clients[nick]
|
||||
return
|
||||
|
||||
nick = params[1]
|
||||
user = params[3]
|
||||
|
@ -196,6 +203,7 @@ moon = require "moon"
|
|||
|
||||
state.channels[name] =
|
||||
:name, :mode, :topic, :key, :limit, members: {}
|
||||
state.channels[name]
|
||||
|
||||
["PRIVMSG"]: (state, sender, params) =>
|
||||
if params[2] == "?state"
|
||||
|
|
|
@ -5,14 +5,14 @@ socket = require "socket"
|
|||
class Server
|
||||
new: (config) =>
|
||||
@config = config
|
||||
socket = socket.tcp!
|
||||
sock = socket.tcp!
|
||||
irc = irce.new!
|
||||
|
||||
irc\load_module require "irce.modules.ngircd"
|
||||
irc\load_module require "ketracel.bots.ketracel"
|
||||
|
||||
irc\set_send_func (message) =>
|
||||
socket\send message
|
||||
sock\send message
|
||||
|
||||
if config.debug
|
||||
ln.log {"msg": "debug enabled"}, config
|
||||
|
@ -22,21 +22,26 @@ class Server
|
|||
|
||||
ln.log msg: "Ketracel loaded", irce: irce._VERSION, lua: _VERSION
|
||||
|
||||
assert socket\connect config.server, 6667
|
||||
assert sock\connect config.server, 6667
|
||||
assert irc\REGISTER config.spass, "ketracel", "0.0.1", config.sname, config.sreal, config.nicklen
|
||||
|
||||
@irc = irc
|
||||
@socket = socket
|
||||
@socket = sock
|
||||
|
||||
wait_for: (event) =>
|
||||
wait_for: (event, checker) =>
|
||||
running = true
|
||||
|
||||
@irc\set_callback event, =>
|
||||
@irc\set_callback event, (...) =>
|
||||
if checker and not checker(...)
|
||||
return
|
||||
print "! got event " .. event if os.getenv "DEBUG"
|
||||
running = false
|
||||
|
||||
while running
|
||||
@irc\process @socket\receive!
|
||||
|
||||
@irc\clear_callback event
|
||||
|
||||
run: =>
|
||||
running = true
|
||||
|
||||
|
|
|
@ -9,32 +9,35 @@ get_client_modules = (irc) ->
|
|||
class Client
|
||||
new: (nick) =>
|
||||
@nick = nick
|
||||
socket = socket.tcp!
|
||||
sock = socket.tcp!
|
||||
irc = irce.new!
|
||||
get_client_modules irc
|
||||
irc\set_send_func (message) =>
|
||||
print string.format "[client %s] > %s", nick, message
|
||||
socket\send message
|
||||
print string.format "[client %s] > %s", nick, message if os.getenv "DEBUG"
|
||||
sock\send message
|
||||
|
||||
socket\connect "127.0.0.1", 6667
|
||||
sock\connect "127.0.0.1", 6667
|
||||
irc\NICK nick
|
||||
irc\USER nick, nick
|
||||
|
||||
@socket = socket
|
||||
@socket = sock
|
||||
@irc = irc
|
||||
|
||||
wait_for: (event) =>
|
||||
wait_for: (event, checker) =>
|
||||
running = true
|
||||
nick = @nick
|
||||
@irc\set_callback event, =>
|
||||
print string.format "[client %s] ! got event %s", nick, event
|
||||
@irc\set_callback event, (...) =>
|
||||
if checker and not checker ...
|
||||
return
|
||||
print string.format "[client %s] ! got event %s", nick, event if os.getenv "DEBUG"
|
||||
running = false
|
||||
|
||||
while running
|
||||
msg = @socket\receive!
|
||||
print string.format "[client %s] < %s", nick, msg
|
||||
msg = assert @socket\receive!
|
||||
print string.format "[client %s] < %s", nick, msg if os.getenv "DEBUG"
|
||||
@irc\process msg
|
||||
|
||||
@irc\clear_callback event
|
||||
|
||||
quit: =>
|
||||
@irc\QUIT "bye"
|
||||
@socket\close!
|
||||
|
|
Loading…
Reference in New Issue