Fix tests
This commit is contained in:
parent
b2e3e995ce
commit
06977c9b44
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user