X-Git-Url: http://www.git.cypherpunks.ru/?p=goircd.git;a=blobdiff_plain;f=daemon_test.go;h=599cbf615376f52813a2721154f7f31b7f7e0c09;hp=3db72cb6b73fee9d3636d6a9a30133ee8e8d5ac9;hb=236377e360e37e16986588a62101926d70ad3489;hpb=b67868201041359c456457b62910866a8e072b2b diff --git a/daemon_test.go b/daemon_test.go index 3db72cb..599cbf6 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -1,11 +1,10 @@ /* goircd -- minimalistic simple Internet Relay Chat (IRC) server -Copyright (C) 2014-2015 Sergey Matveev +Copyright (C) 2014-2020 Sergey Matveev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. +the Free Software Foundation, version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -27,21 +26,24 @@ import ( func TestRegistrationWorkflow(t *testing.T) { host := "foohost" - daemon := NewDaemon("ver1", &host, nil, nil, nil, nil) + hostname = &host events := make(chan ClientEvent) - go daemon.Processor(events) + defer func() { + events <- ClientEvent{eventType: EventTerm} + }() + go Processor(events, make(chan struct{})) conn := NewTestingConn() - client := NewClient(&host, conn) + client := NewClient(conn) go client.Processor(events) - conn.inbound <- "UNEXISTENT CMD" // should recieve nothing on this + conn.inbound <- "UNEXISTENT CMD" // should receive nothing on this conn.inbound <- "NICK" if r := <-conn.outbound; r != ":foohost 431 :No nickname given\r\n" { t.Fatal("431 for NICK", r) } - for _, n := range []string{"привет", " foo", "longlonglong", "#foo", "mein nick", "foo_bar"} { + for _, n := range []string{"привет", " foo", "#foo", "mein nick", "foo_bar"} { conn.inbound <- "NICK " + n if r := <-conn.outbound; r != ":foohost 432 * "+n+" :Erroneous nickname\r\n" { t.Fatal("nickname validation", r) @@ -52,7 +54,7 @@ func TestRegistrationWorkflow(t *testing.T) { if r := <-conn.outbound; r != ":foohost 461 meinick USER :Not enough parameters\r\n" { t.Fatal("461 for USER", r) } - if (client.nickname != "meinick") || client.registered { + if (*client.nickname != "meinick") || client.registered { t.Fatal("NICK saved") } @@ -61,7 +63,7 @@ func TestRegistrationWorkflow(t *testing.T) { t.Fatal("461 again for USER", r) } - daemon.SendLusers(client) + SendLusers(client) if r := <-conn.outbound; !strings.Contains(r, "There are 0 users") { t.Fatal("LUSERS", r) } @@ -85,17 +87,18 @@ func TestRegistrationWorkflow(t *testing.T) { if r := <-conn.outbound; !strings.Contains(r, ":foohost 422") { t.Fatal("422 after registration", r) } - if (client.username != "1") || (client.realname != "4 5") || !client.registered { + if (*client.username != "1") || (*client.realname != "4 5") || !client.registered { t.Fatal("client register") } conn.inbound <- "AWAY" conn.inbound <- "UNEXISTENT CMD" + <-conn.outbound if r := <-conn.outbound; r != ":foohost 421 meinick UNEXISTENT :Unknown command\r\n" { t.Fatal("reply for unexistent command", r) } - daemon.SendLusers(client) + SendLusers(client) if r := <-conn.outbound; !strings.Contains(r, "There are 1 users") { t.Fatal("1 users logged in", r) } @@ -106,10 +109,6 @@ func TestRegistrationWorkflow(t *testing.T) { } conn.inbound <- "QUIT\r\nUNEXISTENT CMD" - <-conn.outbound - if !conn.closed { - t.Fatal("closed connection on QUIT") - } } func TestMotd(t *testing.T) { @@ -122,11 +121,12 @@ func TestMotd(t *testing.T) { conn := NewTestingConn() host := "foohost" - client := NewClient(&host, conn) + hostname = &host + client := NewClient(conn) motdName := fd.Name() - daemon := NewDaemon("ver1", &host, &motdName, nil, nil, nil) + motd = &motdName - daemon.SendMotd(client) + SendMotd(client) if r := <-conn.outbound; !strings.HasPrefix(r, ":foohost 375") { t.Fatal("MOTD start", r) }