goircd/client_test.go

85 lines
2.2 KiB
Go
Raw Normal View History

2014-05-11 16:18:55 +00:00
/*
goircd -- minimalistic simple Internet Relay Chat (IRC) server
2021-01-05 17:48:29 +00:00
Copyright (C) 2014-2021 Sergey Matveev <stargrave@stargrave.org>
2014-05-11 16:18:55 +00:00
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 3 of the License.
2014-05-11 16:18:55 +00:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2015-05-09 15:27:06 +00:00
2014-05-11 16:18:55 +00:00
package main
import (
"testing"
)
func TestNewClient(t *testing.T) {
2014-05-14 12:29:54 +00:00
conn := NewTestingConn()
events := make(chan ClientEvent)
host := "foohost"
hostname = &host
client := NewClient(conn, events)
defer func() {
client.Close()
}()
2014-05-11 16:18:55 +00:00
event := <-events
2014-08-09 12:42:19 +00:00
if event.eventType != EventNew {
2014-05-18 11:27:17 +00:00
t.Fatal("no NEW event", event)
2014-05-11 16:18:55 +00:00
}
2014-05-14 12:29:54 +00:00
conn.inbound <- "foo"
event = <-events
2014-08-09 12:42:19 +00:00
if (event.eventType != EventMsg) || (event.text != "foo") {
2014-05-18 11:27:17 +00:00
t.Fatal("no first MSG", event)
2014-05-11 16:18:55 +00:00
}
2014-05-14 12:29:54 +00:00
conn.inbound <- "bar"
event = <-events
2014-08-09 12:42:19 +00:00
if (event.eventType != EventMsg) || (event.text != "bar") {
2014-05-18 11:27:17 +00:00
t.Fatal("no second MSG", event)
2014-05-11 16:18:55 +00:00
}
2014-05-14 12:29:54 +00:00
conn.inbound <- ""
event = <-events
2014-08-09 12:42:19 +00:00
if event.eventType != EventDel {
2014-05-18 11:27:17 +00:00
t.Fatal("no client termination", event)
2014-05-11 16:18:55 +00:00
}
}
func TestClientReplies(t *testing.T) {
2014-05-14 12:29:54 +00:00
conn := NewTestingConn()
host := "foohost"
hostname = &host
client := NewClient(conn, make(chan ClientEvent, 2))
defer func() {
client.Close()
}()
client.nickname = "мойник"
2014-05-11 16:18:55 +00:00
client.Reply("hello")
2014-05-14 12:29:54 +00:00
if r := <-conn.outbound; r != ":foohost hello\r\n" {
2014-05-18 11:27:17 +00:00
t.Fatal("did not recieve hello message", r)
2014-05-11 16:18:55 +00:00
}
client.ReplyParts("200", "foo", "bar")
2014-05-14 12:29:54 +00:00
if r := <-conn.outbound; r != ":foohost 200 foo :bar\r\n" {
2014-05-18 11:27:17 +00:00
t.Fatal("did not recieve 200 message", r)
2014-05-11 16:18:55 +00:00
}
client.ReplyNicknamed("200", "foo", "bar")
2014-05-14 12:29:54 +00:00
if r := <-conn.outbound; r != ":foohost 200 мойник foo :bar\r\n" {
2014-05-18 11:27:17 +00:00
t.Fatal("did not recieve nicknamed message", r)
2014-05-11 16:18:55 +00:00
}
client.ReplyNotEnoughParameters("CMD")
2014-05-14 12:29:54 +00:00
if r := <-conn.outbound; r != ":foohost 461 мойник CMD :Not enough parameters\r\n" {
2014-05-18 11:27:17 +00:00
t.Fatal("did not recieve 461 message", r)
2014-05-11 16:18:55 +00:00
}
}