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:
parent
6815c19bb3
commit
389f5247f5
2 changed files with 33 additions and 12 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue