forked from cwtch.im/cwtch
1
0
Fork 0
cwtch/storage/message_store_test.go

44 lines
941 B
Go
Raw Permalink 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"
2018-03-09 20:44:13 +00:00
"os"
"strconv"
"testing"
)
func TestMessageStore(t *testing.T) {
os.Remove("ms.test")
ms := new(MessageStore)
2018-06-03 19:36:20 +00:00
ms.Init("ms.test", 100000)
for i := 0; i < 50000; 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)
}
ms.Close()
2018-06-03 19:36:20 +00:00
ms.Init("ms.test", 100000)
2018-03-09 20:44:13 +00:00
m := ms.FetchMessages()
2018-06-03 19:36:20 +00:00
if len(m) != 50000 {
t.Errorf("Should have been 5000 was %v", len(m))
}
for i := 0; i < 100000; i++ {
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()
2018-03-09 20:44:13 +00:00
if len(m) != 100000 {
t.Errorf("Should have been 100000 was %v", len(m))
}
2018-06-03 19:36:20 +00:00
2018-03-09 20:44:13 +00:00
ms.Close()
os.Remove("ms.test")
}