|
@@ -3,12 +3,91 @@ package ircclient
|
|
|
import (
|
|
|
"fmt"
|
|
|
"net"
|
|
|
+ "reflect"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"syscall"
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
|
+func TestParse(t *testing.T) {
|
|
|
+ var Msg IRCMsg
|
|
|
+ var Expect map[string]IRCMsg = map[string]IRCMsg{
|
|
|
+ "PING :78629A0F5F3F164F": IRCMsg{
|
|
|
+ Cmd: "PING", Msg: "78629A0F5F3F164F", MsgParts: []string{"PING"}},
|
|
|
+ ":irc.red-green.com 001 test :Welcome to the RedGreen IRC Network": IRCMsg{
|
|
|
+ From: "irc.red-green.com", Cmd: "001", To: "test",
|
|
|
+ Msg: "Welcome to the RedGreen IRC Network",
|
|
|
+ MsgParts: []string{":irc.red-green.com", "001", "test"}},
|
|
|
+ ":irc.red-green.com 375 test :- irc.red-green.com Message of the Day -": IRCMsg{
|
|
|
+ From: "irc.red-green.com", Cmd: "375", To: "test",
|
|
|
+ Msg: "- irc.red-green.com Message of the Day -",
|
|
|
+ MsgParts: []string{":irc.red-green.com", "375", "test"}},
|
|
|
+ ":irc.red-green.com 433 :Nick already in use": IRCMsg{
|
|
|
+ From: "irc.red-green.com", Cmd: "433",
|
|
|
+ Msg: "Nick already in use",
|
|
|
+ MsgParts: []string{":irc.red-green.com", "433"}},
|
|
|
+ ":NickServ!services@services.red-green.com NOTICE test :Password accepted - you are now recognized.": IRCMsg{
|
|
|
+ From: "NickServ", Cmd: "NOTICE", To: "test",
|
|
|
+ Msg: "Password accepted - you are now recognized.",
|
|
|
+ MsgParts: []string{":NickServ!services@services.red-green.com",
|
|
|
+ "NOTICE", "test"}},
|
|
|
+ ":irc.red-green.com 005 meow-bot HCN INVEX KICKLEN=307 KNOCK MAP MAXCHANNELS=10 MAXLIST=b:60,e:60,I:60 MAXNICKLEN=30 MINNICKLEN=0 MODES=12 NAMESX NETWORK=RedGreen :are supported by this server": IRCMsg{
|
|
|
+ From: "irc.red-green.com", Cmd: "005", To: "meow-bot",
|
|
|
+ Msg: "are supported by this server",
|
|
|
+ MsgParts: []string{":irc.red-green.com", "005", "meow-bot", "HCN", "INVEX",
|
|
|
+ "KICKLEN=307", "KNOCK", "MAP", "MAXCHANNELS=10", "MAXLIST=b:60,e:60,I:60",
|
|
|
+ "MAXNICKLEN=30", "MINNICKLEN=0", "MODES=12", "NAMESX", "NETWORK=RedGreen"}},
|
|
|
+ ":irc.red-green.com 353 meow-bot = #backstage :meow-bot performer5 performer4 performer3 performer1 performer2 Stage_Manager Apollo ~bugz": IRCMsg{
|
|
|
+ From: "irc.red-green.com", Cmd: "353", To: "meow-bot",
|
|
|
+ Msg: "meow-bot performer5 performer4 performer3 performer1 performer2 Stage_Manager Apollo ~bugz",
|
|
|
+ MsgParts: []string{":irc.red-green.com", "353", "meow-bot", "=", "#backstage"}},
|
|
|
+ }
|
|
|
+
|
|
|
+ for line, msgout := range Expect {
|
|
|
+ Msg = IRCParse(line)
|
|
|
+ var fields []string = []string{"To", "From", "Cmd", "Msg"}
|
|
|
+ msg_value := reflect.ValueOf(Msg)
|
|
|
+ msgout_value := reflect.ValueOf(msgout)
|
|
|
+
|
|
|
+ for _, field := range fields {
|
|
|
+ var got string
|
|
|
+ var expect string
|
|
|
+ got = msg_value.FieldByName(field).String()
|
|
|
+ expect = msgout_value.FieldByName(field).String()
|
|
|
+ if got != expect {
|
|
|
+ t.Errorf("%s %s: got %s, expected %s", line, field, got, expect)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if Msg.To != msgout.To {
|
|
|
+ t.Errorf("%s To: got %s, expected %s", line, Msg.To, msgout.To)
|
|
|
+ }
|
|
|
+ if Msg.From != msgout.From {
|
|
|
+ t.Errorf("%s From: got %s, expected %s", line, Msg.From, msgout.From)
|
|
|
+ }
|
|
|
+ if Msg.Cmd != msgout.Cmd {
|
|
|
+ t.Errorf("%s Cmd: got %s, expected %s", line, Msg.Cmd, msgout.Cmd)
|
|
|
+ }
|
|
|
+ if Msg.Msg != msgout.Msg {
|
|
|
+ t.Errorf("%s Msg: got %s, expected %s", line, Msg.Msg, msgout.Msg)
|
|
|
+ }
|
|
|
+ */
|
|
|
+ if len(Msg.MsgParts) != len(msgout.MsgParts) {
|
|
|
+ t.Errorf("%s MsgParts got len %d, expected len %d", line, len(Msg.MsgParts), len(msgout.MsgParts))
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ for idx := range Msg.MsgParts {
|
|
|
+ if Msg.MsgParts[idx] != msgout.MsgParts[idx] {
|
|
|
+ t.Errorf("%s MsgParts[%d] %s, expected %s", line, idx, Msg.MsgParts[idx], msgout.MsgParts[idx])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestConnect(t *testing.T) {
|
|
|
var config IRCConfig = IRCConfig{Nick: "test",
|
|
|
Username: "test",
|
|
@@ -33,12 +112,45 @@ func TestConnect(t *testing.T) {
|
|
|
defer config.Close()
|
|
|
|
|
|
var Msg IRCMsg
|
|
|
- var motd, identify bool
|
|
|
+ var motd, identify, support bool
|
|
|
+ var isupport map[string]string = map[string]string{
|
|
|
+ "AWAYLEN": "307", "BOT": "B", "CASEMAPPING": "ascii",
|
|
|
+ "CHANLIMIT": "#:10", "CHANMODES": "beI,kLf,lH,psmntirzMQNRTOVKDdGPZSCc",
|
|
|
+ "CHANNELLEN": "32", "CHANTYPES": "#", "CLIENTTAGDENY": "*,-draft/typing,-typing",
|
|
|
+ "DEAF": "d", "ELIST": "MNUCT", "EXCEPTS": "", "EXTBAN": "~,GptmTSOcarnqjf",
|
|
|
+ "HCN": "", "INVEX": "", "KICKLEN": "307", "KNOCK": "", "MAP": "", "MAXCHANNELS": "10",
|
|
|
+ "MAXLIST": "b:60,e:60,I:60", "MAXNICKLEN": "30", "MINNICKLEN": "0", "MODES": "12",
|
|
|
+ "NAMESX": "", "NETWORK": "RedGreen", "NICKLEN": "30", "PREFIX": "(qaohv)~&@%+",
|
|
|
+ "QUITLEN": "307", "SAFELIST": "", "SILENCE": "15", "STATUSMSG": "~&@%+",
|
|
|
+ "TARGMAX": "DCCALLOW:,ISON:,JOIN:,KICK:4,KILL:,LIST:,NAMES:1,NOTICE:1,PART:,PRIVMSG:4,SAJOIN:,SAPART:,TAGMSG:1,USERHOST:,USERIP:,WATCH:,WHOIS:1,WHOWAS:1",
|
|
|
+ "TOPICLEN": "360", "UHNAMES": "", "USERIP": "", "WALLCHOPS": "", "WATCH": "128",
|
|
|
+ "WATCHOPTS": "A", "WHOX": "",
|
|
|
+ }
|
|
|
+
|
|
|
for Msg = range FromIRC {
|
|
|
if Msg.Cmd == "EndMOTD" {
|
|
|
t.Log("Got EndMOTD")
|
|
|
motd = true
|
|
|
+
|
|
|
+ support = true
|
|
|
+
|
|
|
+ for key, value := range isupport {
|
|
|
+ var got string
|
|
|
+ var has bool
|
|
|
+ got, has = config.ISupport[key]
|
|
|
+ if !has {
|
|
|
+ t.Errorf("Missing ISUPPORT[%s] expected (%s)", key, value)
|
|
|
+ support = false
|
|
|
+ } else {
|
|
|
+ if got != value {
|
|
|
+ t.Errorf("ISUPPORT[%s] got %s, expected %s", key, got, value)
|
|
|
+ support = false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
if Msg.Cmd == "Identified" {
|
|
|
t.Log("Identified")
|
|
|
identify = true
|
|
@@ -51,7 +163,9 @@ func TestConnect(t *testing.T) {
|
|
|
if !identify {
|
|
|
t.Error("Missing Identified")
|
|
|
}
|
|
|
-
|
|
|
+ if !support {
|
|
|
+ t.Error("Missing ISupport")
|
|
|
+ }
|
|
|
if config.MyNick != config.Nick {
|
|
|
t.Errorf("Got %s, Expected %s", config.MyNick, config.Nick)
|
|
|
}
|