]> Cypherpunks.ru repositories - goircd.git/blobdiff - room_test.go
Many fixes and additions
[goircd.git] / room_test.go
index 969481843f290891ef5307879d5b165ba822a112..97c202b82f19d3321776752a5049063b1914ec4b 100644 (file)
@@ -46,10 +46,9 @@ func TestTwoUsers(t *testing.T) {
        host := "foohost"
        hostname = &host
        events := make(chan ClientEvent)
-       roomsM.Lock()
+       roomsLock.Lock()
        rooms = make(map[string]*Room)
-       roomSinks = make(map[*Room]chan ClientEvent)
-       roomsM.Unlock()
+       roomsLock.Unlock()
        clients = make(map[*Client]struct{})
        finished := make(chan struct{})
        go Processor(events, finished)
@@ -60,10 +59,8 @@ func TestTwoUsers(t *testing.T) {
 
        conn1 := NewTestingConn()
        conn2 := NewTestingConn()
-       client1 := NewClient(conn1)
-       client2 := NewClient(conn2)
-       go client1.Processor(events)
-       go client2.Processor(events)
+       client1 := NewClient(conn1, events)
+       NewClient(conn2, events)
 
        conn1.inbound <- "NICK nick1\r\nUSER foo1 bar1 baz1 :Long name1"
        conn2.inbound <- "NICK nick2\r\nUSER foo2 bar2 baz2 :Long name2"
@@ -72,7 +69,7 @@ func TestTwoUsers(t *testing.T) {
                <-conn2.outbound
        }
 
-       SendLusers(client1)
+       client1.SendLusers()
        if r := <-conn1.outbound; !strings.Contains(r, "There are 2 users") {
                t.Fatal("LUSERS", r)
        }
@@ -139,7 +136,6 @@ func TestJoin(t *testing.T) {
        events := make(chan ClientEvent)
        rooms = make(map[string]*Room)
        clients = make(map[*Client]struct{})
-       roomSinks = make(map[*Room]chan ClientEvent)
        finished := make(chan struct{})
        go Processor(events, finished)
        defer func() {
@@ -147,8 +143,7 @@ func TestJoin(t *testing.T) {
                <-finished
        }()
        conn := NewTestingConn()
-       client := NewClient(conn)
-       go client.Processor(events)
+       NewClient(conn, events)
 
        conn.inbound <- "NICK nick2\r\nUSER foo2 bar2 baz2 :Long name2"
        for i := 0; i < 6; i++ {
@@ -183,14 +178,14 @@ func TestJoin(t *testing.T) {
        for i := 0; i < 4*2; i++ {
                <-conn.outbound
        }
-       roomsM.RLock()
+       roomsLock.RLock()
        if _, ok := rooms["#bar"]; !ok {
                t.Fatal("#bar does not exist")
        }
        if _, ok := rooms["#baz"]; !ok {
                t.Fatal("#baz does not exist")
        }
-       roomsM.RUnlock()
+       roomsLock.RUnlock()
        if r := <-logSink; (r.what != "joined") || (r.where != "#bar") || (r.who != "nick2") || (r.meta != true) {
                t.Fatal("invalid join log event #bar", r)
        }
@@ -202,14 +197,14 @@ func TestJoin(t *testing.T) {
        for i := 0; i < 4*2; i++ {
                <-conn.outbound
        }
-       roomsM.RLock()
-       if *rooms["#barenc"].key != "key1" {
+       roomsLock.RLock()
+       if rooms["#barenc"].key != "key1" {
                t.Fatal("no room with key1")
        }
-       if *rooms["#bazenc"].key != "key2" {
+       if rooms["#bazenc"].key != "key2" {
                t.Fatal("no room with key2")
        }
-       roomsM.RUnlock()
+       roomsLock.RUnlock()
        if r := <-logSink; (r.what != "joined") || (r.where != "#barenc") || (r.who != "nick2") || (r.meta != true) {
                t.Fatal("invalid join log event #barenc", r)
        }
@@ -227,11 +222,11 @@ func TestJoin(t *testing.T) {
        if r := <-conn.outbound; r != ":nick2!foo2@someclient MODE #barenc -k\r\n" {
                t.Fatal("remove #barenc key", r)
        }
-       roomsM.RLock()
-       if *rooms["#barenc"].key != "" {
+       roomsLock.RLock()
+       if rooms["#barenc"].key != "" {
                t.Fatal("removing key from #barenc")
        }
-       roomsM.RUnlock()
+       roomsLock.RUnlock()
        if r := <-logSink; (r.what != "removed channel key") || (r.where != "#barenc") || (r.who != "nick2") || (r.meta != true) {
                t.Fatal("removed channel key log", r)
        }
@@ -240,6 +235,9 @@ func TestJoin(t *testing.T) {
        }
 
        conn.inbound <- "PART #bazenc\r\nMODE #bazenc -k"
+       if r := <-conn.outbound; r != ":nick2!foo2@someclient PART #bazenc :nick2\r\n" {
+               t.Fatal("part", r)
+       }
        if r := <-conn.outbound; r != ":foohost 442 #bazenc :You are not on that channel\r\n" {
                t.Fatal("not on that channel", r)
        }
@@ -256,7 +254,7 @@ func TestJoin(t *testing.T) {
        if r := <-conn.outbound; r != ":nick2!foo2@someclient MODE #barenc +k newkey\r\n" {
                t.Fatal("+k MODE setting", r)
        }
-       if r := <-logSink; (r.what != "set channel key to newkey") || (r.where != "#barenc") || (r.who != "nick2") || (r.meta != true) {
+       if r := <-logSink; (r.what != "set channel key") || (r.where != "#barenc") || (r.who != "nick2") || (r.meta != true) {
                t.Fatal("set channel key", r)
        }
        if r := <-stateSink; (r.topic != "") || (r.where != "#barenc") || (r.key != "newkey") {