From cf8ab830f7c2a11960758d3355603d11c005e85f Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Wed, 24 Aug 2011 13:55:18 +0100 Subject: [PATCH] Move some basic assertions about initial state into setUp(). --- client/connection_test.go | 29 ++++++++++++++++++++++------- client/handlers_test.go | 15 --------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/client/connection_test.go b/client/connection_test.go index 7490af3..3315445 100644 --- a/client/connection_test.go +++ b/client/connection_test.go @@ -10,10 +10,31 @@ func setUp(t *testing.T) (*mockNetConn, *Conn) { c := New("test", "test", "Testing IRC") c.State = t + // Assert some basic things about the initial state of the Conn struct + if c.Me.Nick != "test" || + c.Me.Ident != "test" || + c.Me.Name != "Testing IRC" || + c.Me.Host != "" { + t.Errorf("Conn.Me not correctly initialised.") + } + if len(c.chans) != 0 { + t.Errorf("Some channels are already known:") + for _, ch := range c.chans { + t.Logf(ch.String()) + } + } + if len(c.nicks) != 1 { + t.Errorf("Other Nicks than ourselves exist:") + for _, n := range c.nicks { + t.Logf(n.String()) + } + } + m := MockNetConn(t) c.sock = m - c.Flood = true // Tests can take a while otherwise c.postConnect() + c.Flood = true // Tests can take a while otherwise + c.Connected = true return m, c } @@ -50,9 +71,6 @@ func (conn *Conn) ExpectNoErrors() { func TestShutdown(t *testing.T) { _, c := setUp(t) - // Shutdown won't clean things up unless we're "connected" already - c.Connected = true - // Setup a mock event dispatcher to test correct triggering of "disconnected" flag := false c.Dispatcher = WasEventDispatched("disconnected", &flag) @@ -91,9 +109,6 @@ func TestShutdown(t *testing.T) { func TestEOF(t *testing.T) { m, c := setUp(t) - // Shutdown won't clean things up unless we're "connected" already - c.Connected = true - // Setup a mock event dispatcher to test correct triggering of "disconnected" flag := false c.Dispatcher = WasEventDispatched("disconnected", &flag) diff --git a/client/handlers_test.go b/client/handlers_test.go index 497e946..72a7d30 100644 --- a/client/handlers_test.go +++ b/client/handlers_test.go @@ -24,11 +24,6 @@ func Test001(t *testing.T) { flag := false c.Dispatcher = WasEventDispatched("connected", &flag) - // Assert that the "Host" field of c.Me hasn't been set yet - if c.Me.Host != "" { - t.Errorf("Host field contains unexpected value '%s'.", c.Me.Host) - } - // Call handler with a valid 001 line c.h_001(parseLine(":irc.server.org 001 test :Welcome to IRC test!ident@somehost.com")) // Should result in no response to server @@ -50,11 +45,6 @@ func Test433(t *testing.T) { m, c := setUp(t) defer tearDown(m, c) - // Assert that the nick set in setUp() is still "test" (just in case) - if c.Me.Nick != "test" { - t.Errorf("Tests will fail because Nick != 'test'.") - } - // Call handler with a 433 line, not triggering c.Me.Renick() c.h_433(parseLine(":irc.server.org 433 test new :Nickname is already in use.")) m.Expect("NICK new_") @@ -81,11 +71,6 @@ func TestNICK(t *testing.T) { m, c := setUp(t) defer tearDown(m, c) - // Assert that the nick set in setUp() is still "test" (just in case) - if c.Me.Nick != "test" { - t.Errorf("Tests will fail because Nick != 'test'.") - } - // Call handler with a NICK line changing "our" nick to test1. c.h_NICK(parseLine(":test!test@somehost.com NICK :test1")) // Should generate no errors and no response to server