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.

stream_store_test.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package storage
  2. import (
  3. "cwtch.im/cwtch/model"
  4. "os"
  5. "testing"
  6. )
  7. const testingDir = "./testing"
  8. const filenameBase = "testStream"
  9. const password = "asdfqwer"
  10. const line1 = "Hello from storage!"
  11. func TestStreamStoreWriteRead(t *testing.T) {
  12. os.Remove(".test.json")
  13. os.RemoveAll(testingDir)
  14. os.Mkdir(testingDir, 0777)
  15. ss1 := NewStreamStore(testingDir, filenameBase, password)
  16. m := model.Message{Message: line1}
  17. ss1.Write(m)
  18. ss2 := NewStreamStore(testingDir, filenameBase, password)
  19. messages := ss2.Read()
  20. if len(messages) != 1 {
  21. t.Errorf("Read messages has wrong length. Expected: 1 Actual: %d\n", len(messages))
  22. }
  23. if messages[0].Message != line1 {
  24. t.Errorf("Read message has wrong content. Expected: '%v' Actual: '%v'\n", line1, messages[0].Message)
  25. }
  26. }
  27. func TestStreamStoreWriteReadRotate(t *testing.T) {
  28. os.Remove(".test.json")
  29. os.RemoveAll(testingDir)
  30. os.Mkdir(testingDir, 0777)
  31. ss1 := NewStreamStore(testingDir, filenameBase, password)
  32. m := model.Message{Message: line1}
  33. for i := 0; i < 400; i++ {
  34. ss1.Write(m)
  35. }
  36. ss2 := NewStreamStore(testingDir, filenameBase, password)
  37. messages := ss2.Read()
  38. if len(messages) != 400 {
  39. t.Errorf("Read messages has wrong length. Expected: 400 Actual: %d\n", len(messages))
  40. }
  41. if messages[0].Message != line1 {
  42. t.Errorf("Read message has wrong content. Expected: '%v' Actual: '%v'\n", line1, messages[0].Message)
  43. }
  44. }