Make call checker a handler.

This commit is contained in:
Alex Bramley 2021-03-26 12:40:28 +00:00
parent 1a10eba91a
commit 5bb083547b
1 changed files with 7 additions and 9 deletions

View File

@ -24,6 +24,10 @@ func (c checker) call() {
c.c <- struct{}{} c.c <- struct{}{}
} }
func (c checker) Handle(_ *Conn, _ *Line) {
c.call()
}
func (c checker) assertNotCalled(fmt string, args ...interface{}) { func (c checker) assertNotCalled(fmt string, args ...interface{}) {
select { select {
case <-c.c: case <-c.c:
@ -85,9 +89,7 @@ func TestEOF(t *testing.T) {
// Set up a handler to detect whether disconnected handlers are called // Set up a handler to detect whether disconnected handlers are called
dcon := callCheck(t) dcon := callCheck(t)
c.HandleFunc(DISCONNECTED, func(conn *Conn, line *Line) { c.Handle(DISCONNECTED, dcon)
dcon.call()
})
// Simulate EOF from server // Simulate EOF from server
s.nc.Close() s.nc.Close()
@ -460,14 +462,10 @@ func TestRunLoop(t *testing.T) {
// Don't use 001 here, since there's already a handler for that // Don't use 001 here, since there's already a handler for that
// and it hangs this test unless we mock the state tracker calls. // and it hangs this test unless we mock the state tracker calls.
h002 := callCheck(t) h002 := callCheck(t)
c.HandleFunc("002", func(conn *Conn, line *Line) { c.Handle("002", h002)
h002.call()
})
h003 := callCheck(t) h003 := callCheck(t)
// Set up a handler to detect whether 002 handler is called // Set up a handler to detect whether 002 handler is called
c.HandleFunc("003", func(conn *Conn, line *Line) { c.Handle("003", h003)
h003.call()
})
l2 := ParseLine(":irc.server.org 002 test :First test line.") l2 := ParseLine(":irc.server.org 002 test :First test line.")
c.in <- l2 c.in <- l2