]> Cypherpunks.ru repositories - goircd.git/blobdiff - daemon_test.go
Unify copyright comment format
[goircd.git] / daemon_test.go
index e48d22dde0c3642e1ebbf4cabefa6053b74e8af6..b67fbd4664743662709cd8890b220aa3acbf8072 100644 (file)
@@ -1,25 +1,21 @@
-/*
-goircd -- minimalistic simple Internet Relay Chat (IRC) server
-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
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-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/>.
-*/
+// goircd -- minimalistic simple Internet Relay Chat (IRC) server
+// Copyright (C) 2014-2024 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
+// 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
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// 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 (
-       "io/ioutil"
        "os"
        "strings"
        "testing"
@@ -29,13 +25,14 @@ func TestRegistrationWorkflow(t *testing.T) {
        host := "foohost"
        hostname = &host
        events := make(chan ClientEvent)
+       finished := make(chan struct{})
        defer func() {
                events <- ClientEvent{eventType: EventTerm}
+               <-finished
        }()
-       go Processor(events, make(chan struct{}))
+       go Processor(events, finished)
        conn := NewTestingConn()
-       client := NewClient(conn)
-       go client.Processor(events)
+       client := NewClient(conn, events)
 
        conn.inbound <- "UNEXISTENT CMD" // should receive nothing on this
        conn.inbound <- "NICK"
@@ -55,7 +52,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")
        }
 
@@ -64,7 +61,7 @@ func TestRegistrationWorkflow(t *testing.T) {
                t.Fatal("461 again for USER", r)
        }
 
-       SendLusers(client)
+       client.SendLusers()
        if r := <-conn.outbound; !strings.Contains(r, "There are 0 users") {
                t.Fatal("LUSERS", r)
        }
@@ -88,7 +85,7 @@ 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")
        }
 
@@ -99,7 +96,7 @@ func TestRegistrationWorkflow(t *testing.T) {
                t.Fatal("reply for unexistent command", r)
        }
 
-       SendLusers(client)
+       client.SendLusers()
        if r := <-conn.outbound; !strings.Contains(r, "There are 1 users") {
                t.Fatal("1 users logged in", r)
        }
@@ -113,7 +110,7 @@ func TestRegistrationWorkflow(t *testing.T) {
 }
 
 func TestMotd(t *testing.T) {
-       fd, err := ioutil.TempFile("", "motd")
+       fd, err := os.CreateTemp("", "motd")
        if err != nil {
                t.Fatalf("can not create temporary file: %v", err)
        }
@@ -123,11 +120,14 @@ func TestMotd(t *testing.T) {
        conn := NewTestingConn()
        host := "foohost"
        hostname = &host
-       client := NewClient(conn)
+       client := NewClient(conn, make(chan ClientEvent, 2))
+       defer func() {
+               client.Close()
+       }()
        motdName := fd.Name()
        motd = &motdName
 
-       SendMotd(client)
+       client.SendMotd()
        if r := <-conn.outbound; !strings.HasPrefix(r, ":foohost 375") {
                t.Fatal("MOTD start", r)
        }