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(), Name: "testName", InvitationId: "testInvitationId", MyName: "testMyName", ContactPublicKey: "testContactPublicKey", } 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)) } if peers[0].Uid != peer.Uid { t.Errorf("Expected peer to have uid %s, got %s", peer.Uid, peers[0].Uid) } if peers[0].MyName != peer.MyName { t.Errorf("Expected peer to have MyName %s, got %s", peer.MyName, peers[0].MyName) } }