104 lines
2.1 KiB
Go
104 lines
2.1 KiB
Go
package client
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"testing"
|
|
|
|
"forge.redroom.link/yves/meowlib"
|
|
)
|
|
|
|
func TestGetUid(t *testing.T) {
|
|
srv := Server{
|
|
Name: "test",
|
|
Url: "http://127.0.0.1:8080",
|
|
PublicKey: meowlib.NewKeyPair().Public,
|
|
}
|
|
uid := srv.GetUid()
|
|
if uid != "http://127.0.0.1:8080" {
|
|
log.Fatal("uid not correct")
|
|
}
|
|
}
|
|
|
|
func TestStoreServer(t *testing.T) {
|
|
GetConfig().SetMemPass("test")
|
|
ss := ServerStorage{DbFile: "test.db"}
|
|
srv := Server{
|
|
Name: "test",
|
|
Url: "http://127.0.0.1",
|
|
PublicKey: meowlib.NewKeyPair().Public,
|
|
}
|
|
err := ss.StoreServer(&srv)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
sout, err := ss.LoadServer(srv.GetServerCard().GetUid())
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if sout == nil {
|
|
log.Fatal("server not found")
|
|
}
|
|
if sout.Name != srv.Name {
|
|
log.Fatal("name not found")
|
|
}
|
|
// Clean up
|
|
// recursively remove the test.db folder
|
|
os.RemoveAll("test.db")
|
|
}
|
|
|
|
func TestLoadServersFromUids(t *testing.T) {
|
|
GetConfig().SetMemPass("test")
|
|
ss := ServerStorage{DbFile: "test.db"}
|
|
srv := Server{
|
|
Name: "test",
|
|
Url: "http://localhost:8080",
|
|
PublicKey: meowlib.NewKeyPair().Public,
|
|
}
|
|
err := ss.StoreServer(&srv)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
sout, err := ss.LoadServersFromUids([]string{srv.GetServerCard().GetUid()})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if sout == nil {
|
|
log.Fatal("server not found")
|
|
}
|
|
if sout[0].Name != srv.Name {
|
|
log.Fatal("name not found")
|
|
}
|
|
// Clean up
|
|
// recursively remove the test.db folder
|
|
os.RemoveAll("test.db")
|
|
}
|
|
|
|
func TestLoadServerCardsFromUids(t *testing.T) {
|
|
GetConfig().SetMemPass("test")
|
|
ss := ServerStorage{DbFile: "test.db"}
|
|
srv := Server{
|
|
Name: "test",
|
|
Url: "http://localhost:8080",
|
|
PublicKey: meowlib.NewKeyPair().Public,
|
|
}
|
|
err := ss.StoreServer(&srv)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
sout, err := ss.LoadServerCardsFromUids([]string{srv.GetServerCard().GetUid()})
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if sout == nil {
|
|
log.Fatal("server not found")
|
|
}
|
|
if sout[0].Name != srv.Name {
|
|
log.Fatal("name not found")
|
|
}
|
|
// Clean up
|
|
// recursively remove the test.db folder
|
|
os.RemoveAll("test.db")
|
|
}
|