mirror of https://github.com/fluffle/goirc
Add mock dispatcher factory that tests an event fired; use it in Test001().
This commit is contained in:
parent
59b18b038b
commit
5ff77fc2f9
|
@ -1,6 +1,9 @@
|
|||
package client
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func setUp(t *testing.T) (*mockNetConn, *Conn) {
|
||||
c := New("test", "test", "Testing IRC")
|
||||
|
@ -17,3 +20,11 @@ type mockDispatcher func(string, ...interface{})
|
|||
func (d mockDispatcher) Dispatch(name string, ev ...interface{}) {
|
||||
d(name, ev...)
|
||||
}
|
||||
|
||||
func WasEventDispatched(name string, flag *bool) mockDispatcher {
|
||||
return mockDispatcher(func(n string, ev ...interface{}) {
|
||||
if n == strings.ToLower(name) {
|
||||
*flag = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -20,12 +20,8 @@ func Test001(t *testing.T) {
|
|||
_, c := setUp(t)
|
||||
|
||||
// Setup a mock event dispatcher to test correct triggering of "connected"
|
||||
connected := false
|
||||
c.Dispatcher = mockDispatcher(func(name string, ev ...interface{}) {
|
||||
if name == "connected" {
|
||||
connected = true
|
||||
}
|
||||
})
|
||||
flag := false
|
||||
c.Dispatcher = WasEventDispatched("connected", &flag)
|
||||
|
||||
// Assert that the "Host" field of c.Me hasn't been set yet
|
||||
if c.Me.Host != "" {
|
||||
|
@ -36,7 +32,7 @@ func Test001(t *testing.T) {
|
|||
c.h_001(parseLine(":irc.server.org 001 test :Welcome to IRC test!ident@somehost.com"))
|
||||
|
||||
// Check that the event was dispatched correctly
|
||||
if !connected {
|
||||
if !flag {
|
||||
t.Errorf("Sending 001 didn't result in dispatch of connected event.")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue