]> Cypherpunks.ru repositories - goircd.git/blob - client_test.go
ISON command support
[goircd.git] / client_test.go
1 /*
2 goircd -- minimalistic simple Internet Relay Chat (IRC) server
3 Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
4
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.
9
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.
14
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/>.
17 */
18
19 package main
20
21 import (
22         "testing"
23 )
24
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)
30         host := "foohost"
31         hostname = &host
32         client := NewClient(conn)
33         go client.Processor(sink)
34
35         event := <-sink
36         if event.eventType != EventNew {
37                 t.Fatal("no NEW event", event)
38         }
39         conn.inbound <- "foo"
40         event = <-sink
41         if (event.eventType != EventMsg) || (event.text != "foo") {
42                 t.Fatal("no first MSG", event)
43         }
44         conn.inbound <- "bar"
45         event = <-sink
46         if (event.eventType != EventMsg) || (event.text != "bar") {
47                 t.Fatal("no second MSG", event)
48         }
49         conn.inbound <- ""
50         event = <-sink
51         if event.eventType != EventDel {
52                 t.Fatal("no client termination", event)
53         }
54 }
55
56 // Test replies formatting
57 func TestClientReplies(t *testing.T) {
58         conn := NewTestingConn()
59         host := "foohost"
60         hostname = &host
61         client := NewClient(conn)
62         nickname := "мойник"
63         client.nickname = &nickname
64
65         client.Reply("hello")
66         if r := <-conn.outbound; r != ":foohost hello\r\n" {
67                 t.Fatal("did not recieve hello message", r)
68         }
69
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)
73         }
74
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)
78         }
79
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)
83         }
84 }