X-Git-Url: http://www.git.cypherpunks.ru/?p=goircd.git;a=blobdiff_plain;f=daemon_test.go;h=76d620305dcf83725ef3e43f7d68e21028f4b6d3;hp=599cbf615376f52813a2721154f7f31b7f7e0c09;hb=b7fb219307483d2c31b5dad1f559f325f2fd1a5e;hpb=def58d0f4944397faa8cdd4a9cf3515125e0b548 diff --git a/daemon_test.go b/daemon_test.go index 599cbf6..76d6203 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -28,13 +28,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 +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") } @@ -63,7 +64,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 +88,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 +99,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) } @@ -122,11 +123,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) }