X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=daemon_test.go;h=db8401351831c3026d2e391f3719ba3bf1800e13;hb=6f9d7fae374e5ada6c33f585db748f23fbc49f91;hp=d851d59c434e03f6d4bbb3ed3c97e5ae15e6a8eb;hpb=7a081293793cbf329b964ce0de6338425609374f;p=goircd.git diff --git a/daemon_test.go b/daemon_test.go index d851d59..db84013 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -1,6 +1,6 @@ /* goircd -- minimalistic simple Internet Relay Chat (IRC) server -Copyright (C) 2014-2019 Sergey Matveev +Copyright (C) 2014-2022 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 @@ -18,7 +18,6 @@ along with this program. If not, see . package main import ( - "io/ioutil" "os" "strings" "testing" @@ -28,13 +27,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" @@ -54,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") } @@ -63,7 +63,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) } @@ -87,7 +87,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") } @@ -98,7 +98,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) } @@ -112,7 +112,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) } @@ -122,11 +122,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) }