Test for INIT handler and some minor style nits.

This commit is contained in:
Alex Bramley 2013-02-16 10:25:35 +00:00
parent 93f8683068
commit 666549398a
3 changed files with 22 additions and 4 deletions

View File

@ -180,8 +180,6 @@ func (conn *Conn) Connect(host string, pass ...string) error {
conn.Host = host conn.Host = host
if len(pass) > 0 { if len(pass) > 0 {
conn.password = pass[0] conn.password = pass[0]
} else {
conn.password = ""
} }
conn.Connected = true conn.Connected = true
conn.postConnect() conn.postConnect()

View File

@ -44,7 +44,7 @@ var intHandlers map[string]event.Handler
func init() { func init() {
intHandlers = make(map[string]event.Handler) intHandlers = make(map[string]event.Handler)
intHandlers[INIT] = NewHandler((*Conn).h_init) intHandlers[INIT] = NewHandler((*Conn).h_INIT)
intHandlers["001"] = NewHandler((*Conn).h_001) intHandlers["001"] = NewHandler((*Conn).h_001)
intHandlers["433"] = NewHandler((*Conn).h_433) intHandlers["433"] = NewHandler((*Conn).h_433)
intHandlers["CTCP"] = NewHandler((*Conn).h_CTCP) intHandlers["CTCP"] = NewHandler((*Conn).h_CTCP)
@ -59,7 +59,7 @@ func (conn *Conn) addIntHandlers() {
} }
// Password/User/Nick broadcast on connection. // Password/User/Nick broadcast on connection.
func (conn *Conn) h_init(line *Line) { func (conn *Conn) h_INIT(line *Line) {
if conn.password != "" { if conn.password != "" {
conn.Pass(conn.password) conn.Pass(conn.password)
} }

View File

@ -21,6 +21,26 @@ func TestPING(t *testing.T) {
c.ED = s.ed c.ED = s.ed
} }
// Test that the inbuilt INIT handler does the right things
func TestINIT(t *testing.T) {
c, s := setUp(t)
defer s.tearDown()
c.h_INIT(&Line{})
s.nc.Expect("NICK test")
s.nc.Expect("USER test 12 * :Testing IRC")
s.nc.ExpectNothing()
c.password = "12345"
c.Me.Ident = "idiot"
c.Me.Name = "I've got the same combination on my luggage!"
c.h_INIT(&Line{})
s.nc.Expect("PASS 12345")
s.nc.Expect("NICK test")
s.nc.Expect("USER idiot 12 * :I've got the same combination on my luggage!")
s.nc.ExpectNothing()
}
// Test the handler for 001 / RPL_WELCOME // Test the handler for 001 / RPL_WELCOME
func Test001(t *testing.T) { func Test001(t *testing.T) {
c, s := setUp(t) c, s := setUp(t)