Refactor GetUid() method and add new tests for server storage
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
423ef5c4b1
commit
df9c6b5d46
@ -7,6 +7,18 @@ import (
|
|||||||
"forge.redroom.link/yves/meowlib"
|
"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) {
|
func TestStoreServer(t *testing.T) {
|
||||||
GetConfig().SetMemPass("test")
|
GetConfig().SetMemPass("test")
|
||||||
ss := ServerStorage{DbFile: "test.db"}
|
ss := ServerStorage{DbFile: "test.db"}
|
||||||
@ -19,6 +31,7 @@ func TestStoreServer(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
sout, err := ss.LoadServer(srv.GetServerCard().GetUid())
|
sout, err := ss.LoadServer(srv.GetServerCard().GetUid())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -31,3 +44,51 @@ func TestStoreServer(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
1064
client/test.id
1064
client/test.id
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,10 @@
|
|||||||
package meowlib
|
package meowlib
|
||||||
|
|
||||||
func (sc *ServerCard) GetUid() string {
|
func (sc *ServerCard) GetUid() string {
|
||||||
return sc.Login + ":" + sc.Password + "@" + sc.Url
|
if len(sc.Login) > 0 || len(sc.Password) > 0 {
|
||||||
|
return sc.Login + ":" + sc.Password + "@" + sc.Url
|
||||||
|
}
|
||||||
|
return sc.Url
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *ServerCard) IsSame(sc1 *ServerCard) bool {
|
func (sc *ServerCard) IsSame(sc1 *ServerCard) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user