50 lines
829 B
Go
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))
|
||
|
}
|
||
|
}
|