1 // goircd -- minimalistic simple Internet Relay Chat (IRC) server
2 // Copyright (C) 2014-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 func TestNewClient(t *testing.T) {
23 conn := NewTestingConn()
24 events := make(chan ClientEvent)
27 client := NewClient(conn, events)
33 if event.eventType != EventNew {
34 t.Fatal("no NEW event", event)
38 if (event.eventType != EventMsg) || (event.text != "foo") {
39 t.Fatal("no first MSG", event)
43 if (event.eventType != EventMsg) || (event.text != "bar") {
44 t.Fatal("no second MSG", event)
48 if event.eventType != EventDel {
49 t.Fatal("no client termination", event)
53 func TestClientReplies(t *testing.T) {
54 conn := NewTestingConn()
57 client := NewClient(conn, make(chan ClientEvent, 2))
61 client.nickname = "мойник"
64 if r := <-conn.outbound; r != ":foohost hello\r\n" {
65 t.Fatal("did not recieve hello message", r)
68 client.ReplyParts("200", "foo", "bar")
69 if r := <-conn.outbound; r != ":foohost 200 foo :bar\r\n" {
70 t.Fatal("did not recieve 200 message", r)
73 client.ReplyNicknamed("200", "foo", "bar")
74 if r := <-conn.outbound; r != ":foohost 200 мойник foo :bar\r\n" {
75 t.Fatal("did not recieve nicknamed message", r)
78 client.ReplyNotEnoughParameters("CMD")
79 if r := <-conn.outbound; r != ":foohost 461 мойник CMD :Not enough parameters\r\n" {
80 t.Fatal("did not recieve 461 message", r)