Commit 105515d5 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Add unit test for chat history.

parent 60297a24
...@@ -2,6 +2,7 @@ package group ...@@ -2,6 +2,7 @@ package group
import ( import (
"encoding/json" "encoding/json"
"fmt"
"reflect" "reflect"
"testing" "testing"
"time" "time"
...@@ -23,6 +24,27 @@ func TestJSTime(t *testing.T) { ...@@ -23,6 +24,27 @@ func TestJSTime(t *testing.T) {
} }
} }
func TestChatHistory(t *testing.T) {
g := Group{
description: &description{},
}
for i := 0; i < 2*maxChatHistory; i++ {
g.AddToChatHistory("id", "user", ToJSTime(time.Now()), "",
fmt.Sprintf("%v", i),
)
}
h := g.GetChatHistory()
if len(h) != maxChatHistory {
t.Errorf("Expected %v, got %v", maxChatHistory, len(g.history))
}
for i, s := range h {
e := fmt.Sprintf("%v", i+maxChatHistory)
if s.Value.(string) != e {
t.Errorf("Expected %v, got %v", e, s)
}
}
}
var descJSON = ` var descJSON = `
{ {
"op": [{"username": "jch","password": "topsecret"}], "op": [{"username": "jch","password": "topsecret"}],
...@@ -117,7 +139,6 @@ var goodClients = []testClientPerm{ ...@@ -117,7 +139,6 @@ var goodClients = []testClientPerm{
}, },
} }
func TestPermissions(t *testing.T) { func TestPermissions(t *testing.T) {
var d description var d description
err := json.Unmarshal([]byte(descJSON), &d) err := json.Unmarshal([]byte(descJSON), &d)
...@@ -126,7 +147,7 @@ func TestPermissions(t *testing.T) { ...@@ -126,7 +147,7 @@ func TestPermissions(t *testing.T) {
} }
for _, c := range badClients { for _, c := range badClients {
t.Run("bad " + c.Username(), func(t *testing.T) { t.Run("bad "+c.Username(), func(t *testing.T) {
p, err := d.GetPermission("test", c) p, err := d.GetPermission("test", c)
if err != ErrNotAuthorised { if err != ErrNotAuthorised {
t.Errorf("GetPermission %v: %v %v", c, err, p) t.Errorf("GetPermission %v: %v %v", c, err, p)
...@@ -135,7 +156,7 @@ func TestPermissions(t *testing.T) { ...@@ -135,7 +156,7 @@ func TestPermissions(t *testing.T) {
} }
for _, cp := range goodClients { for _, cp := range goodClients {
t.Run("good " + cp.c.Username(), func(t *testing.T) { t.Run("good "+cp.c.Username(), func(t *testing.T) {
p, err := d.GetPermission("test", cp.c) p, err := d.GetPermission("test", cp.c)
if err != nil { if err != nil {
t.Errorf("GetPermission %v: %v", cp.c, err) t.Errorf("GetPermission %v: %v", cp.c, err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment