write peer storage test + fix loading
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2024-05-28 18:39:32 +02:00
parent 78a8b797e6
commit e9624e4576
3 changed files with 50 additions and 57 deletions

View File

@ -134,7 +134,7 @@ func (ps *PeerStorage) LoadPeers(password string) ([]*Peer, error) {
}
return json.Unmarshal(jsonsrv, &sc)
})
if err != nil {
if err == nil {
peers = append(peers, &sc)
ps.cache[sc.Uid] = &sc
}

View File

@ -0,0 +1,49 @@
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))
}
}

View File

@ -1,56 +0,0 @@
-----BEGIN PGP MESSAGE-----
Version: GopenPGP 2.7.5
Comment: https://gopenpgp.org
wy4ECQMIcaNS6eJQEW3gAXJII8nUZfT633pLElEvApbeK86TbdlNH5d0qAYnicub
0usBU48qJk76au+qwpy5pk9JjISPW92hxTEvla6YgKaRvwtcx2gxHeJSSOZEL0AD
36AlYCc9OiwObvYi1G1f84ZqzOW1GVtgB7BmKttCz2d30zLuXClagRTISAsMjs2F
N5WUhbymXAG1Xd7GfZUsb5mfzgOVM5MPgtkaXwPlSKYEJmM2F3GaSbPOhiI9DWIw
JAOWiSXsrU1p3HBcAWWdEK0MENlJRbgvJCi7d5aVjiHksb5+8W9cvZxBVrK/aTW6
zRwJ04pW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