cwtch/server/storage/message_store_test.go

57 lines
1.2 KiB
Go
Raw Normal View History

2018-03-09 20:44:13 +00:00
package storage
import (
2018-05-28 18:05:06 +00:00
"cwtch.im/cwtch/protocol"
"cwtch.im/cwtch/server/metrics"
2018-03-09 20:44:13 +00:00
"os"
"strconv"
"testing"
)
func TestMessageStore(t *testing.T) {
os.Remove("ms.test")
ms := new(MessageStore)
counter := metrics.NewCounter()
ms.Init("./", 1000, counter)
for i := 0; i < 499; i++ {
2018-03-09 20:44:13 +00:00
gm := protocol.GroupMessage{
Ciphertext: []byte("Hello this is a fairly average length message that we are writing here. " + strconv.Itoa(i)),
Spamguard: []byte{},
}
ms.AddMessage(gm)
}
if counter.Count() != 499 {
t.Errorf("Counter should be at 499 was %v", counter.Count())
}
2018-03-09 20:44:13 +00:00
ms.Close()
ms.Init("./", 1000, counter)
2018-03-09 20:44:13 +00:00
m := ms.FetchMessages()
if len(m) != 499 {
t.Errorf("Should have been 499 was %v", len(m))
2018-06-03 19:36:20 +00:00
}
counter.Reset()
for i := 0; i < 1000; i++ {
2018-06-03 19:36:20 +00:00
gm := protocol.GroupMessage{
Ciphertext: []byte("Hello this is a fairly average length message that we are writing here. " + strconv.Itoa(i)),
Spamguard: []byte{},
}
ms.AddMessage(gm)
}
m = ms.FetchMessages()
if len(m) != 1000 {
t.Errorf("Should have been 1000 was %v", len(m))
2018-03-09 20:44:13 +00:00
}
ms.Close()
ms.Init("./", 1000, counter)
m = ms.FetchMessages()
if len(m) != 999 {
t.Errorf("Should have been 999 was %v", len(m))
}
ms.Close()
os.RemoveAll("./messages")
2018-03-09 20:44:13 +00:00
}