2 goircd -- minimalistic simple Internet Relay Chat (IRC) server
3 Copyright (C) 2014-2015 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, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 // New client creation test. It must send an event about new client,
26 // two predefined messages from it and deletion one
27 func TestNewClient(t *testing.T) {
28 conn := NewTestingConn()
29 sink := make(chan ClientEvent)
32 client := NewClient(conn)
33 go client.Processor(sink)
36 if event.eventType != EventNew {
37 t.Fatal("no NEW event", event)
41 if (event.eventType != EventMsg) || (event.text != "foo") {
42 t.Fatal("no first MSG", event)
46 if (event.eventType != EventMsg) || (event.text != "bar") {
47 t.Fatal("no second MSG", event)
51 if event.eventType != EventDel {
52 t.Fatal("no client termination", event)
56 // Test replies formatting
57 func TestClientReplies(t *testing.T) {
58 conn := NewTestingConn()
61 client := NewClient(conn)
63 client.nickname = &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)