meowlib/client/storage_test.go

47 lines
886 B
Go
Raw Normal View History

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")
err := StoreMessage(&id.Peers[0], &um, GetConfig().memoryPassword)
if err != nil {
log.Fatal(err)
}
messages, err := GetLastMessages(&id.Peers[0], 0, 0, 10, GetConfig().memoryPassword)
if err != nil {
log.Fatal(err)
}
// Checks
assert.Equal(t, len(messages), 1, "not 1 message")
assert.Equal(t, messages[0].message.Data, um.Data, "not 1 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)
}
}
}
func TestGetLastMessages(t *testing.T) {
}