2 goircd -- minimalistic simple Internet Relay Chat (IRC) server
3 Copyright (C) 2014-2022 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 func TestNewClient(t *testing.T) {
25 conn := NewTestingConn()
26 events := make(chan ClientEvent)
29 client := NewClient(conn, events)
35 if event.eventType != EventNew {
36 t.Fatal("no NEW event", event)
40 if (event.eventType != EventMsg) || (event.text != "foo") {
41 t.Fatal("no first MSG", event)
45 if (event.eventType != EventMsg) || (event.text != "bar") {
46 t.Fatal("no second MSG", event)
50 if event.eventType != EventDel {
51 t.Fatal("no client termination", event)
55 func TestClientReplies(t *testing.T) {
56 conn := NewTestingConn()
59 client := NewClient(conn, make(chan ClientEvent, 2))
63 client.nickname = "мойник"
66 if r := <-conn.outbound; r != ":foohost hello\r\n" {
67 t.Fatal("did not recieve hello message", r)
70 client.ReplyParts("200", "foo", "bar")
71 if r := <-conn.outbound; r != ":foohost 200 foo :bar\r\n" {
72 t.Fatal("did not recieve 200 message", r)
75 client.ReplyNicknamed("200", "foo", "bar")
76 if r := <-conn.outbound; r != ":foohost 200 мойник foo :bar\r\n" {
77 t.Fatal("did not recieve nicknamed message", r)
80 client.ReplyNotEnoughParameters("CMD")
81 if r := <-conn.outbound; r != ":foohost 461 мойник CMD :Not enough parameters\r\n" {
82 t.Fatal("did not recieve 461 message", r)