Fix tests

This commit is contained in:
Ken-Håvard Lieng 2017-04-13 01:59:16 +02:00
parent b2e3e995ce
commit 06977c9b44
2 changed files with 14 additions and 5 deletions

View File

@ -128,7 +128,7 @@ func TestRecv(t *testing.T) {
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
buf.WriteString("CMD\r\n") buf.WriteString("CMD\r\n")
buf.WriteString("PING :test\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.reader = bufio.NewReader(buf)
c.ready.Add(1) c.ready.Add(1)

View File

@ -35,13 +35,17 @@ func TestMain(m *testing.M) {
} }
func dispatchMessage(msg *irc.Message) WSResponse { func dispatchMessage(msg *irc.Message) WSResponse {
return <-dispatchMessageMulti(msg)
}
func dispatchMessageMulti(msg *irc.Message) chan WSResponse {
c := irc.NewClient("nick", "user") c := irc.NewClient("nick", "user")
c.Host = "host.com" c.Host = "host.com"
s := NewSession(user) s := NewSession(user)
newIRCHandler(c, s).dispatchMessage(msg) newIRCHandler(c, s).dispatchMessage(msg)
return <-s.broadcast return s.broadcast
} }
func checkResponse(t *testing.T, expectedType string, expectedData interface{}, res WSResponse) { 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) { func TestHandleIRCWelcome(t *testing.T) {
res := dispatchMessage(&irc.Message{ res := dispatchMessageMulti(&irc.Message{
Command: irc.ReplyWelcome, Command: irc.ReplyWelcome,
Nick: "nick", 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{ checkResponse(t, "pm", Chat{
Server: "host.com", Server: "host.com",
From: "nick", From: "nick",
Message: "some text", Message: "some text",
}, res) }, <-res)
} }
func TestHandleIRCWhois(t *testing.T) { func TestHandleIRCWhois(t *testing.T) {