summaryrefslogtreecommitdiff
path: root/chat/chat_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'chat/chat_test.go')
-rw-r--r--chat/chat_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/chat/chat_test.go b/chat/chat_test.go
new file mode 100644
index 0000000..b695b44
--- /dev/null
+++ b/chat/chat_test.go
@@ -0,0 +1,50 @@
+package chat
+
+import (
+ "testing"
+)
+
+func TestJoining(t *testing.T) {
+ InitRooms(2)
+
+ b1, r1, err := Join("test", "Foo")
+ if err != nil {
+ t.Fatalf("Could not join room: %s", err)
+ }
+ defer b1.Leave()
+
+ if _, _, err = Join("test", "Foo"); err != NickAlreadyInUse {
+ t.Fatalf("Got error \"%s\", expected \"%s\"", err, NickAlreadyInUse)
+ }
+
+ b2, r2, err := Join("test", "Bar")
+ if err != nil {
+ t.Fatalf("Could not join room a second time: %s", err)
+ }
+ defer b2.Leave()
+
+ // since we joined to the same room, r1 and r2 should be equal
+ if r1 != r2 {
+ t.Error("r1 and r2 are not equal")
+ }
+
+ if _, _, err = Join("test", "Baz"); err != RoomIsFull {
+ t.Fatalf("Got error \"%s\", expected \"%s\"", err, RoomIsFull)
+ }
+}
+
+func TestLeaving(t *testing.T) {
+ InitRooms(10)
+
+ b1, _, err := Join("test", "Foo")
+ if err != nil {
+ t.Fatalf("Could not join room: %s", err)
+ }
+
+ b1.Leave()
+
+ // The room is now empty. It should no longer exist.
+ if _, ok := rooms["test"]; ok {
+ t.Error("Room test still exists, although no user is left")
+ }
+}