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

Convert conn.Err into logging.

Also, remove all error-side-effect testing cos it was a bit shit.
First step on the long road to refactoring the nick/chan state tracking
and making everything more testable and mockable with interfaces.
This commit is contained in:
Alex Bramley 2011-09-29 22:54:54 +01:00
parent 9773b47969
commit de66051d07
6 changed files with 75 additions and 160 deletions

View file

@ -1,11 +1,18 @@
package client
import (
"github.com/fluffle/goirc/logging"
"strings"
"testing"
"time"
)
func init() {
// We have Error level logging that is printed on socket shutdown
// which we don't care too much about when testing with a mock conn...
logging.SetLogLevel(logging.LogFatal)
}
func setUp(t *testing.T) (*mockNetConn, *Conn) {
c := New("test", "test", "Testing IRC")
c.State = t
@ -39,33 +46,7 @@ func setUp(t *testing.T) (*mockNetConn, *Conn) {
}
func tearDown(m *mockNetConn, c *Conn) {
// This is enough to cause all the associated goroutines in m and c stop
// (tested below in TestShutdown to make sure this is the case)
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)
}
c.shutdown()
}
func TestShutdown(t *testing.T) {
@ -78,18 +59,6 @@ func TestShutdown(t *testing.T) {
// Call shutdown manually
c.shutdown()
// Check that we get an EOF from Read()
timer := time.NewTimer(5e6)
select {
case <-timer.C:
t.Errorf("No error received for shutdown.")
case err := <-c.Err:
timer.Stop()
if err.String() != "irc.recv(): EOF" {
t.Errorf("Expected EOF, got: %s", err)
}
}
// Verify that the connection no longer thinks it's connected
if c.Connected {
t.Errorf("Conn still thinks it's connected to the server.")
@ -116,17 +85,9 @@ func TestEOF(t *testing.T) {
// Simulate EOF from server
m.Close()
// Check that we get an EOF from Read()
timer := time.NewTimer(5e6)
select {
case <-timer.C:
t.Errorf("No error received for shutdown.")
case err := <-c.Err:
timer.Stop()
if err.String() != "irc.recv(): EOF" {
t.Errorf("Expected EOF, got: %s", err)
}
}
// Since things happen in different internal goroutines, we need to wait
// 1 ms should be enough :-)
time.Sleep(1e6)
// Verify that the connection no longer thinks it's connected
if c.Connected {