1
0
Fork 0
mirror of https://github.com/fluffle/goirc synced 2025-05-14 11:33:20 +00:00

Helpers for testing whether Conn errors are triggered.

This commit is contained in:
Alex Bramley 2011-08-24 13:53:28 +01:00
parent 6815c19bb3
commit 389f5247f5
2 changed files with 33 additions and 12 deletions

View file

@ -8,6 +8,8 @@ import (
func setUp(t *testing.T) (*mockNetConn, *Conn) {
c := New("test", "test", "Testing IRC")
c.State = t
m := MockNetConn(t)
c.sock = m
c.Flood = true // Tests can take a while otherwise
@ -21,6 +23,30 @@ func tearDown(m *mockNetConn, c *Conn) {
m.Close()
}
func (conn *Conn) ExpectError() {
// With the current error handling, we could block on reading the Err
// channel, so ensure we don't wait forever with a 5ms timeout.
t := conn.State.(*testing.T)
timer := time.NewTimer(5e6)
select {
case <-timer.C:
t.Errorf("Error expected on Err channel, none received.")
case <-conn.Err:
timer.Stop()
}
}
func (conn *Conn) ExpectNoErrors() {
t := conn.State.(*testing.T)
timer := time.NewTimer(5e6)
select {
case <-timer.C:
case err := <-conn.Err:
timer.Stop()
t.Errorf("No error expected on Err channel, received:\n\t%s", err)
}
}
func TestShutdown(t *testing.T) {
_, c := setUp(t)