2 goircd -- minimalistic simple Internet Relay Chat (IRC) server
3 Copyright (C) 2014-2019 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 // New client creation test. It must send an event about new client,
25 // two predefined messages from it and deletion one
26 func TestNewClient(t *testing.T) {
27 conn := NewTestingConn()
28 sink := make(chan ClientEvent)
31 client := NewClient(conn)
32 go client.Processor(sink)
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 // Test replies formatting
56 func TestClientReplies(t *testing.T) {
57 conn := NewTestingConn()
60 client := NewClient(conn)
62 client.nickname = &nickname
65 if r := <-conn.outbound; r != ":foohost hello\r\n" {
66 t.Fatal("did not recieve hello message", r)
69 client.ReplyParts("200", "foo", "bar")
70 if r := <-conn.outbound; r != ":foohost 200 foo :bar\r\n" {
71 t.Fatal("did not recieve 200 message", r)
74 client.ReplyNicknamed("200", "foo", "bar")
75 if r := <-conn.outbound; r != ":foohost 200 мойник foo :bar\r\n" {
76 t.Fatal("did not recieve nicknamed message", r)
79 client.ReplyNotEnoughParameters("CMD")
80 if r := <-conn.outbound; r != ":foohost 461 мойник CMD :Not enough parameters\r\n" {
81 t.Fatal("did not recieve 461 message", r)