meowlib/client/peerstorage_test.go
ycc e9624e4576
Some checks failed
continuous-integration/drone/push Build is failing
write peer storage test + fix loading
2024-05-28 18:39:32 +02:00

50 lines
829 B
Go

package client
import (
"testing"
"github.com/google/uuid"
)
func TestOpen(t *testing.T) {
ps := &PeerStorage{
DbFile: "peerdb.test",
cache: nil,
db: nil,
}
err := ps.open()
if err != nil {
t.Errorf("Failed to open database: %v", err)
}
}
func TestStorePeer(t *testing.T) {
id := createId()
GetConfig().SetMemPass("test")
GetConfig().SetIdentity(id)
ps := &PeerStorage{
DbFile: "peerdb.test",
cache: nil,
db: nil,
}
peer := &Peer{
Uid: uuid.New().String(),
}
err := ps.StorePeer(peer)
if err != nil {
t.Errorf("Failed to store peer: %v", err)
}
// load the peer from the database
peers, err := ps.LoadPeers(GetConfig().GetMemPass())
if err != nil {
t.Errorf("Failed to load peers: %v", err)
}
if len(peers) != 1 {
t.Errorf("Expected 1 peer, got %d", len(peers))
}
}