catching empty arguments in IRC() + tests
This commit is contained in:
parent
ceacb7cda1
commit
a4d40a90d5
11
irc.go
11
irc.go
@ -359,8 +359,17 @@ func (irc *Connection) Connect(server string) error {
|
||||
|
||||
|
||||
// Create a connection with the (publicly visible) nickname and username.
|
||||
// The nickname is later used to address the user.
|
||||
// The nickname is later used to address the user. Returns nil if nick
|
||||
// or user are empty.
|
||||
func IRC(nick, user string) *Connection {
|
||||
// catch invalid values
|
||||
if 0 == len(nick) {
|
||||
return nil
|
||||
}
|
||||
if 0 == len(user) {
|
||||
return nil
|
||||
}
|
||||
|
||||
irc := &Connection{
|
||||
nick: nick,
|
||||
user: user,
|
||||
|
35
irc_test.go
35
irc_test.go
@ -127,3 +127,38 @@ func TestClearCallback(t *testing.T) {
|
||||
t.Error("Callbacks not cleared")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIRCemptyNick(t *testing.T) {
|
||||
irccon := IRC("", "go-eventirc")
|
||||
irccon = nil
|
||||
if nil != irccon {
|
||||
t.Error("empty nick didn't result in error")
|
||||
t.Fail()
|
||||
}
|
||||
/*
|
||||
irccon.VerboseCallbackHandler = true
|
||||
irccon.Debug = true
|
||||
irccon.UseTLS = true
|
||||
err := irccon.Connect("irc.freenode.net:7000")
|
||||
if err != nil {
|
||||
t.Fatal("Can't connect to freenode.")
|
||||
}
|
||||
irccon.AddCallback("001", func(e *Event) { irccon.Join("#go-eventirc") })
|
||||
|
||||
irccon.AddCallback("366", func(e *Event) {
|
||||
irccon.Privmsg("#go-eventirc", "Test Message\n")
|
||||
time.Sleep(2 * time.Second)
|
||||
irccon.Quit()
|
||||
})
|
||||
|
||||
irccon.Loop()
|
||||
*/
|
||||
}
|
||||
|
||||
func TestIRCemptyUser(t *testing.T) {
|
||||
irccon := IRC("go-eventirc", "")
|
||||
irccon = nil
|
||||
if nil != irccon {
|
||||
t.Error("empty user didn't result in error")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user