add identity folder creation
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc 2024-03-29 18:26:41 +01:00
parent 385c5f3298
commit a5cfbf854d
3 changed files with 19 additions and 6 deletions

View File

@ -35,7 +35,7 @@ type Identity struct {
unlockedHiddenPeers PeerList unlockedHiddenPeers PeerList
} }
func CreateIdentity(nickname string) *Identity { func CreateIdentity(nickname string) (*Identity, error) {
var id Identity var id Identity
id.Nickname = nickname id.Nickname = nickname
id.Uuid = uuid.New().String() id.Uuid = uuid.New().String()
@ -43,7 +43,11 @@ func CreateIdentity(nickname string) *Identity {
GetConfig().me = &id GetConfig().me = &id
id.MessageServers = ServerStorage{DbFile: uuid.NewString()} id.MessageServers = ServerStorage{DbFile: uuid.NewString()}
id.generateRandomHiddenStuff() id.generateRandomHiddenStuff()
return &id err := id.CreateFolder()
if err != nil {
return nil, err
}
return &id, nil
} }
func (id *Identity) CreateFolder() error { func (id *Identity) CreateFolder() error {

View File

@ -24,8 +24,11 @@ func createId() *Identity {
config.memoryPassword = "generalPassword" config.memoryPassword = "generalPassword"
// ! Extension to quickly open db : Debug only ! // ! Extension to quickly open db : Debug only !
config.DbSuffix = ".sqlite" config.DbSuffix = ".sqlite"
id := CreateIdentity("myname") id, err := CreateIdentity("myname")
err := id.Save() if err != nil {
log.Fatal("CreateIdentity failed")
}
err = id.Save()
if err != nil { if err != nil {
log.Fatal("Save failed") log.Fatal("Save failed")
} }
@ -49,7 +52,10 @@ func TestLoad(t *testing.T) {
} }
id, err := LoadIdentity("test.id", "toto") id, err := LoadIdentity("test.id", "toto")
if err != nil { if err != nil {
id := CreateIdentity("myname") id, err1 := CreateIdentity("myname")
if err1 != nil {
log.Fatal("CreateIdentity failed")
}
id.Save() id.Save()
} else { } else {
log.Println(id.Nickname) log.Println(id.Nickname)

View File

@ -8,7 +8,10 @@ import (
) )
func TestGetFromPublicKey(t *testing.T) { func TestGetFromPublicKey(t *testing.T) {
id := CreateIdentity("test") id, err := CreateIdentity("test")
if err != nil {
t.Fatal("CreateIdentity failed")
}
id.Save() id.Save()
for i := 1; i < 10; i++ { for i := 1; i < 10; i++ {
var p Peer var p Peer