Official cwtch.im peer and server implementations. https://cwtch.im
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.2KB

  1. package storage
  2. import (
  3. "cwtch.im/cwtch/protocol"
  4. "cwtch.im/cwtch/server/metrics"
  5. "os"
  6. "strconv"
  7. "testing"
  8. )
  9. func TestMessageStore(t *testing.T) {
  10. os.Remove("ms.test")
  11. ms := new(MessageStore)
  12. counter := metrics.NewCounter()
  13. ms.Init("./", 1000, counter)
  14. for i := 0; i < 499; i++ {
  15. gm := protocol.GroupMessage{
  16. Ciphertext: []byte("Hello this is a fairly average length message that we are writing here. " + strconv.Itoa(i)),
  17. Spamguard: []byte{},
  18. }
  19. ms.AddMessage(gm)
  20. }
  21. if counter.Count() != 499 {
  22. t.Errorf("Counter should be at 499 was %v", counter.Count())
  23. }
  24. ms.Close()
  25. ms.Init("./", 1000, counter)
  26. m := ms.FetchMessages()
  27. if len(m) != 499 {
  28. t.Errorf("Should have been 499 was %v", len(m))
  29. }
  30. counter.Reset()
  31. for i := 0; i < 1000; i++ {
  32. gm := protocol.GroupMessage{
  33. Ciphertext: []byte("Hello this is a fairly average length message that we are writing here. " + strconv.Itoa(i)),
  34. Spamguard: []byte{},
  35. }
  36. ms.AddMessage(gm)
  37. }
  38. m = ms.FetchMessages()
  39. if len(m) != 1000 {
  40. t.Errorf("Should have been 1000 was %v", len(m))
  41. }
  42. ms.Close()
  43. ms.Init("./", 1000, counter)
  44. m = ms.FetchMessages()
  45. if len(m) != 999 {
  46. t.Errorf("Should have been 999 was %v", len(m))
  47. }
  48. ms.Close()
  49. os.RemoveAll("./messages")
  50. }