]> Cypherpunks.ru repositories - goircd.git/blobdiff - room_test.go
Refactored and corrected client's network data reading
[goircd.git] / room_test.go
index 0ad2cacc0364d5b6b410ee7b5f894184218b5a6c..d94e8d49634d24ef836cbb899d31bff9752b4a23 100644 (file)
@@ -1,3 +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/>.
+*/
+
 package main
 
 import (
@@ -26,19 +44,20 @@ func notEnoughParams(t *testing.T, c *TestingConn) {
 func TestTwoUsers(t *testing.T) {
        logSink := make(chan LogEvent, 8)
        stateSink := make(chan StateEvent, 8)
-       daemon := NewDaemon("ver1", "foohost", "", logSink, stateSink)
+       host := "foohost"
+       daemon := NewDaemon("ver1", &host, nil, nil, logSink, stateSink)
        events := make(chan ClientEvent)
        go daemon.Processor(events)
 
        conn1 := NewTestingConn()
        conn2 := NewTestingConn()
-       client1 := NewClient("foohost", conn1)
-       client2 := NewClient("foohost", conn2)
+       client1 := NewClient(&host, conn1)
+       client2 := NewClient(&host, conn2)
        go client1.Processor(events)
        go client2.Processor(events)
 
-       conn1.inbound <- "NICK nick1\r\nUSER foo1 bar1 baz1 :Long name1\r\n"
-       conn2.inbound <- "NICK nick2\r\nUSER foo2 bar2 baz2 :Long name2\r\n"
+       conn1.inbound <- "NICK nick1\r\nUSER foo1 bar1 baz1 :Long name1"
+       conn2.inbound <- "NICK nick2\r\nUSER foo2 bar2 baz2 :Long name2"
        for i := 0; i < 6; i++ {
                <-conn1.outbound
                <-conn2.outbound
@@ -86,6 +105,7 @@ func TestTwoUsers(t *testing.T) {
        conn1.inbound <- "PRIVMSG nick2 :Hello"
        conn1.inbound <- "PRIVMSG #foo :world"
        conn1.inbound <- "NOTICE #foo :world"
+       <-conn2.outbound
        if r := <-conn2.outbound; r != ":nick1!foo1@someclient PRIVMSG nick2 :Hello\r\n" {
                t.Fatal("first message", r)
        }
@@ -100,14 +120,15 @@ func TestTwoUsers(t *testing.T) {
 func TestJoin(t *testing.T) {
        logSink := make(chan LogEvent, 8)
        stateSink := make(chan StateEvent, 8)
-       daemon := NewDaemon("ver1", "foohost", "", logSink, stateSink)
+       host := "foohost"
+       daemon := NewDaemon("ver1", &host, nil, nil, logSink, stateSink)
        events := make(chan ClientEvent)
        go daemon.Processor(events)
        conn := NewTestingConn()
-       client := NewClient("foohost", conn)
+       client := NewClient(&host, conn)
        go client.Processor(events)
 
-       conn.inbound <- "NICK nick2\r\nUSER foo2 bar2 baz2 :Long name2\r\n"
+       conn.inbound <- "NICK nick2\r\nUSER foo2 bar2 baz2 :Long name2"
        for i := 0; i < 6; i++ {
                <-conn.outbound
        }
@@ -198,8 +219,8 @@ func TestJoin(t *testing.T) {
                t.Fatal("left #bazenc log", r)
        }
 
-       conn.inbound <- "MODE #barenc +b"
-       if r := <-conn.outbound; r != ":foohost 472 nick2 +b :Unknown MODE flag\r\n" {
+       conn.inbound <- "MODE #barenc +i"
+       if r := <-conn.outbound; r != ":foohost 472 nick2 +i :Unknown MODE flag\r\n" {
                t.Fatal("unknown MODE flag", r)
        }