]> Cypherpunks.ru repositories - goircd.git/blobdiff - daemon_test.go
ISON command support
[goircd.git] / daemon_test.go
index d049e42be2f38abe06aad2806b85ed659adddb22..e48d22dde0c3642e1ebbf4cabefa6053b74e8af6 100644 (file)
@@ -1,6 +1,6 @@
 /*
 goircd -- minimalistic simple Internet Relay Chat (IRC) server
-Copyright (C) 2014 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
 
 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
@@ -15,6 +15,7 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
+
 package main
 
 import (
@@ -25,21 +26,25 @@ import (
 )
 
 func TestRegistrationWorkflow(t *testing.T) {
-       daemon := NewDaemon("ver1", "foohost", "", nil, nil)
+       host := "foohost"
+       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("foohost", 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)
@@ -50,7 +55,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")
        }
 
@@ -59,7 +64,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)
        }
@@ -83,17 +88,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)
        }
@@ -104,10 +110,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) {
@@ -119,10 +121,13 @@ func TestMotd(t *testing.T) {
        fd.WriteString("catched\n")
 
        conn := NewTestingConn()
-       client := NewClient("foohost", conn)
-       daemon := NewDaemon("ver1", "foohost", fd.Name(), nil, nil)
+       host := "foohost"
+       hostname = &host
+       client := NewClient(conn)
+       motdName := fd.Name()
+       motd = &motdName
 
-       daemon.SendMotd(client)
+       SendMotd(client)
        if r := <-conn.outbound; !strings.HasPrefix(r, ":foohost 375") {
                t.Fatal("MOTD start", r)
        }