From 06977c9b449bbc696079d2f4026cc2548c71914b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Thu, 13 Apr 2017 01:59:16 +0200 Subject: [PATCH] Fix tests --- irc/conn_test.go | 2 +- server/irc_handler_test.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/irc/conn_test.go b/irc/conn_test.go index 43f29297..c56a792a 100644 --- a/irc/conn_test.go +++ b/irc/conn_test.go @@ -128,7 +128,7 @@ func TestRecv(t *testing.T) { buf := &bytes.Buffer{} buf.WriteString("CMD\r\n") buf.WriteString("PING :test\r\n") - buf.WriteString("001\r\n") + buf.WriteString("001 foo\r\n") c.reader = bufio.NewReader(buf) c.ready.Add(1) diff --git a/server/irc_handler_test.go b/server/irc_handler_test.go index 9e0157a8..db01f428 100644 --- a/server/irc_handler_test.go +++ b/server/irc_handler_test.go @@ -35,13 +35,17 @@ func TestMain(m *testing.M) { } func dispatchMessage(msg *irc.Message) WSResponse { + return <-dispatchMessageMulti(msg) +} + +func dispatchMessageMulti(msg *irc.Message) chan WSResponse { c := irc.NewClient("nick", "user") c.Host = "host.com" s := NewSession(user) newIRCHandler(c, s).dispatchMessage(msg) - return <-s.broadcast + return s.broadcast } func checkResponse(t *testing.T, expectedType string, expectedData interface{}, res WSResponse) { @@ -161,17 +165,22 @@ func TestHandleIRCQuit(t *testing.T) { } func TestHandleIRCWelcome(t *testing.T) { - res := dispatchMessage(&irc.Message{ + res := dispatchMessageMulti(&irc.Message{ Command: irc.ReplyWelcome, Nick: "nick", - Params: []string{"target", "some", "text"}, + Params: []string{"nick", "some", "text"}, }) + checkResponse(t, "nick", Nick{ + Server: "host.com", + New: "nick", + }, <-res) + checkResponse(t, "pm", Chat{ Server: "host.com", From: "nick", Message: "some text", - }, res) + }, <-res) } func TestHandleIRCWhois(t *testing.T) {