]> Cypherpunks.ru repositories - goircd.git/blobdiff - room_test.go
Raise copyright years
[goircd.git] / room_test.go
index 8d6deccc4c8008bda9ad0cf521de6c1f172486dd..969481843f290891ef5307879d5b165ba822a112 100644 (file)
@@ -1,11 +1,10 @@
 /*
 goircd -- minimalistic simple Internet Relay Chat (IRC) server
-Copyright (C) 2014-2015 Sergey Matveev <stargrave@stargrave.org>
+Copyright (C) 2014-2020 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.
+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
@@ -47,9 +46,11 @@ func TestTwoUsers(t *testing.T) {
        host := "foohost"
        hostname = &host
        events := make(chan ClientEvent)
+       roomsM.Lock()
        rooms = make(map[string]*Room)
-       clients = make(map[*Client]struct{})
        roomSinks = make(map[*Room]chan ClientEvent)
+       roomsM.Unlock()
+       clients = make(map[*Client]struct{})
        finished := make(chan struct{})
        go Processor(events, finished)
        defer func() {
@@ -182,12 +183,14 @@ func TestJoin(t *testing.T) {
        for i := 0; i < 4*2; i++ {
                <-conn.outbound
        }
+       roomsM.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()
        if r := <-logSink; (r.what != "joined") || (r.where != "#bar") || (r.who != "nick2") || (r.meta != true) {
                t.Fatal("invalid join log event #bar", r)
        }
@@ -199,12 +202,14 @@ func TestJoin(t *testing.T) {
        for i := 0; i < 4*2; i++ {
                <-conn.outbound
        }
+       roomsM.RLock()
        if *rooms["#barenc"].key != "key1" {
                t.Fatal("no room with key1")
        }
        if *rooms["#bazenc"].key != "key2" {
                t.Fatal("no room with key2")
        }
+       roomsM.RUnlock()
        if r := <-logSink; (r.what != "joined") || (r.where != "#barenc") || (r.who != "nick2") || (r.meta != true) {
                t.Fatal("invalid join log event #barenc", r)
        }
@@ -222,9 +227,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 != "" {
                t.Fatal("removing key from #barenc")
        }
+       roomsM.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)
        }