From 666549398ab399748d7070d0aca5421ec05d59d3 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Sat, 16 Feb 2013 10:25:35 +0000 Subject: [PATCH] Test for INIT handler and some minor style nits. --- client/connection.go | 2 -- client/handlers.go | 4 ++-- client/handlers_test.go | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/client/connection.go b/client/connection.go index 8a407f6..7cbfa21 100644 --- a/client/connection.go +++ b/client/connection.go @@ -180,8 +180,6 @@ func (conn *Conn) Connect(host string, pass ...string) error { conn.Host = host if len(pass) > 0 { conn.password = pass[0] - } else { - conn.password = "" } conn.Connected = true conn.postConnect() diff --git a/client/handlers.go b/client/handlers.go index d4a3c9d..028267b 100644 --- a/client/handlers.go +++ b/client/handlers.go @@ -44,7 +44,7 @@ var intHandlers map[string]event.Handler func init() { 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["433"] = NewHandler((*Conn).h_433) intHandlers["CTCP"] = NewHandler((*Conn).h_CTCP) @@ -59,7 +59,7 @@ func (conn *Conn) addIntHandlers() { } // Password/User/Nick broadcast on connection. -func (conn *Conn) h_init(line *Line) { +func (conn *Conn) h_INIT(line *Line) { if conn.password != "" { conn.Pass(conn.password) } diff --git a/client/handlers_test.go b/client/handlers_test.go index 1d7e082..8fdfef8 100644 --- a/client/handlers_test.go +++ b/client/handlers_test.go @@ -21,6 +21,26 @@ func TestPING(t *testing.T) { 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 func Test001(t *testing.T) { c, s := setUp(t)