2 goircd -- minimalistic simple Internet Relay Chat (IRC) server
3 Copyright (C) 2014 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/>.
29 func TestRegistrationWorkflow(t *testing.T) {
30 daemon := NewDaemon("foohost", "", nil, nil)
31 events := make(chan ClientEvent)
32 go daemon.Processor(events)
33 conn := NewTestingConn()
34 client := NewClient("foohost", conn)
36 events <- ClientEvent{client, EVENT_NEW, ""}
37 events <- ClientEvent{client, EVENT_MSG, "UNEXISTENT CMD"}
39 if len(conn.incoming) > 0 {
43 events <- ClientEvent{client, EVENT_MSG, "NICK"}
45 if (len(conn.incoming) != 1) || (conn.incoming[0] != ":foohost 431 :No nickname given\r\n") {
49 events <- ClientEvent{client, EVENT_MSG, "NICK meinick"}
51 if (len(conn.incoming) != 1) || (client.nickname != "meinick") || client.registered {
55 events <- ClientEvent{client, EVENT_MSG, "USER"}
57 if (len(conn.incoming) != 2) || (conn.incoming[1] != ":foohost 461 meinick USER :Not enough parameters\r\n") {
61 events <- ClientEvent{client, EVENT_MSG, "USER 1 2 3"}
63 if (len(conn.incoming) != 3) || (conn.incoming[2] != ":foohost 461 meinick USER :Not enough parameters\r\n") {
67 daemon.SendLusers(client)
68 if !strings.Contains(conn.incoming[len(conn.incoming)-1], "There are 0 users") {
72 events <- ClientEvent{client, EVENT_MSG, "USER 1 2 3 :4 5"}
74 if (len(conn.incoming) < 4) || (client.username != "1") || (client.realname != "4 5") {
78 statuses := map[int]bool{1: false, 2: false, 3: false, 4: false, 251: false, 422: false}
79 for _, msg := range conn.incoming {
80 for k, _ := range statuses {
81 if strings.HasPrefix(msg, fmt.Sprintf(":foohost %03d", k)) {
86 for _, v := range statuses {
91 if !client.registered {
95 events <- ClientEvent{client, EVENT_MSG, "UNEXISTENT CMD"}
97 if conn.incoming[len(conn.incoming)-1] != ":foohost 421 meinick UNEXISTENT :Unknown command\r\n" {
101 events <- ClientEvent{client, EVENT_MSG, "AWAY"}
103 if conn.incoming[len(conn.incoming)-1] == ":foohost 421 meinick AWAY :Unknown command\r\n" {
107 daemon.SendLusers(client)
108 if !strings.Contains(conn.incoming[len(conn.incoming)-1], "There are 1 users") {
112 events <- ClientEvent{client, EVENT_MSG, "QUIT"}
119 func TestMotd(t *testing.T) {
120 fd, err := ioutil.TempFile("", "motd")
122 t.Fatal("can not create temporary file")
124 defer os.Remove(fd.Name())
125 fd.Write([]byte("catched\n"))
126 daemon := NewDaemon("foohost", fd.Name(), nil, nil)
127 conn := NewTestingConn()
128 client := NewClient("foohost", conn)
130 daemon.SendMotd(client)
132 for _, msg := range conn.incoming {
133 if strings.Contains(msg, "372 * :- catched") {