mirror of https://github.com/fluffle/goirc
Move some basic assertions about initial state into setUp().
This commit is contained in:
parent
389f5247f5
commit
cf8ab830f7
|
@ -10,10 +10,31 @@ func setUp(t *testing.T) (*mockNetConn, *Conn) {
|
||||||
c := New("test", "test", "Testing IRC")
|
c := New("test", "test", "Testing IRC")
|
||||||
c.State = t
|
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)
|
m := MockNetConn(t)
|
||||||
c.sock = m
|
c.sock = m
|
||||||
c.Flood = true // Tests can take a while otherwise
|
|
||||||
c.postConnect()
|
c.postConnect()
|
||||||
|
c.Flood = true // Tests can take a while otherwise
|
||||||
|
c.Connected = true
|
||||||
return m, c
|
return m, c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,9 +71,6 @@ func (conn *Conn) ExpectNoErrors() {
|
||||||
func TestShutdown(t *testing.T) {
|
func TestShutdown(t *testing.T) {
|
||||||
_, c := setUp(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"
|
// Setup a mock event dispatcher to test correct triggering of "disconnected"
|
||||||
flag := false
|
flag := false
|
||||||
c.Dispatcher = WasEventDispatched("disconnected", &flag)
|
c.Dispatcher = WasEventDispatched("disconnected", &flag)
|
||||||
|
@ -91,9 +109,6 @@ func TestShutdown(t *testing.T) {
|
||||||
func TestEOF(t *testing.T) {
|
func TestEOF(t *testing.T) {
|
||||||
m, c := setUp(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"
|
// Setup a mock event dispatcher to test correct triggering of "disconnected"
|
||||||
flag := false
|
flag := false
|
||||||
c.Dispatcher = WasEventDispatched("disconnected", &flag)
|
c.Dispatcher = WasEventDispatched("disconnected", &flag)
|
||||||
|
|
|
@ -24,11 +24,6 @@ func Test001(t *testing.T) {
|
||||||
flag := false
|
flag := false
|
||||||
c.Dispatcher = WasEventDispatched("connected", &flag)
|
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
|
// Call handler with a valid 001 line
|
||||||
c.h_001(parseLine(":irc.server.org 001 test :Welcome to IRC test!ident@somehost.com"))
|
c.h_001(parseLine(":irc.server.org 001 test :Welcome to IRC test!ident@somehost.com"))
|
||||||
// Should result in no response to server
|
// Should result in no response to server
|
||||||
|
@ -50,11 +45,6 @@ func Test433(t *testing.T) {
|
||||||
m, c := setUp(t)
|
m, c := setUp(t)
|
||||||
defer tearDown(m, c)
|
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()
|
// 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."))
|
c.h_433(parseLine(":irc.server.org 433 test new :Nickname is already in use."))
|
||||||
m.Expect("NICK new_")
|
m.Expect("NICK new_")
|
||||||
|
@ -81,11 +71,6 @@ func TestNICK(t *testing.T) {
|
||||||
m, c := setUp(t)
|
m, c := setUp(t)
|
||||||
defer tearDown(m, c)
|
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.
|
// Call handler with a NICK line changing "our" nick to test1.
|
||||||
c.h_NICK(parseLine(":test!test@somehost.com NICK :test1"))
|
c.h_NICK(parseLine(":test!test@somehost.com NICK :test1"))
|
||||||
// Should generate no errors and no response to server
|
// Should generate no errors and no response to server
|
||||||
|
|
Loading…
Reference in New Issue