2023-02-15 22:08:17 +01:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"forge.redroom.link/yves/meowlib"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStoreMessage(t *testing.T) {
|
|
|
|
id := createId()
|
|
|
|
var um meowlib.UserMessage
|
|
|
|
um.Data = []byte("blabla")
|
2024-02-29 21:03:15 +01:00
|
|
|
err := StoreMessage(&id.Peers[0], &um, []string{}, GetConfig().memoryPassword)
|
2023-02-15 22:08:17 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2024-02-17 19:30:25 +01:00
|
|
|
messages, err := GetMessagesHistory(&id.Peers[0], 0, 0, 10, GetConfig().memoryPassword)
|
2023-02-15 22:08:17 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
// Checks
|
|
|
|
assert.Equal(t, len(messages), 1, "not 1 message")
|
2024-02-29 21:03:15 +01:00
|
|
|
assert.Equal(t, messages[0].Message, string(um.Data), "not 1 message")
|
2023-02-15 22:08:17 +01:00
|
|
|
// Cleanup
|
|
|
|
if exists("test.id") {
|
|
|
|
os.Remove("test.id")
|
|
|
|
}
|
|
|
|
files, err := filepath.Glob("*.sqlite")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
for _, f := range files {
|
|
|
|
if err := os.Remove(f); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-17 22:30:13 +01:00
|
|
|
func TestManyStoreMessage(t *testing.T) {
|
|
|
|
id := createId()
|
|
|
|
for i := 1; i < 100; i++ {
|
|
|
|
var um meowlib.UserMessage
|
|
|
|
um.Data = []byte(randomLenString(20, 200))
|
2024-02-29 21:03:15 +01:00
|
|
|
err := StoreMessage(&id.Peers[0], &um, []string{}, GetConfig().memoryPassword)
|
2023-02-17 22:30:13 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2024-02-17 19:30:25 +01:00
|
|
|
messages, err := GetMessagesHistory(&id.Peers[0], 0, 0, 10, GetConfig().memoryPassword)
|
2023-02-17 22:30:13 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
// Checks
|
|
|
|
assert.Equal(t, len(messages), 10, "not 10 message")
|
|
|
|
// Cleanup
|
|
|
|
if exists("test.id") {
|
|
|
|
os.Remove("test.id")
|
|
|
|
}
|
|
|
|
files, err := filepath.Glob("*.sqlite")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
for _, f := range files {
|
|
|
|
if err := os.Remove(f); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
2023-02-15 22:08:17 +01:00
|
|
|
}
|