storage get messages + config improve + tests
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2023-02-15 22:08:17 +01:00
parent d9155bac51
commit 6f2a65dac9
8 changed files with 175 additions and 832 deletions

View File

@ -17,6 +17,31 @@ func exists(filename string) bool {
}
}
func createId() *Identity {
config := GetConfig()
config.IdentityFile = "test.id"
config.memoryPassword = "generalPassword"
// ! Extension to quickly open db : Debug only !
config.DbSuffix = ".sqlite"
id := CreateIdentity("myname")
err := id.Save()
if err != nil {
log.Fatal("Save failed")
}
var p Peer
p.Name = "testName"
p.MyEncryptionKp = meowlib.NewKeyPair()
p.MyIdentity = meowlib.NewKeyPair()
p.MyLookupKp = meowlib.NewKeyPair()
p.Contact.Name = "foo"
p.Contact.ContactPublicKey = p.MyLookupKp.Public
p.Contact.EncryptionPublicKey = p.MyIdentity.Public
p.Contact.LookupPublicKey = p.MyEncryptionKp.Public
p.Contact.AddUrls([]string{"http:/127.0.0.1/meow", "tcp://localhost:1234"})
id.Peers = append(id.Peers, p)
return id
}
func TestLoad(t *testing.T) {
if exists("test.id") {
os.Remove("test.id")
@ -40,19 +65,8 @@ func TestLoad(t *testing.T) {
}
func TestHidePeer(t *testing.T) {
id := CreateIdentity("myname")
id.Save()
var p Peer
p.Name = "testName"
p.MyEncryptionKp = meowlib.NewKeyPair()
p.MyIdentity = meowlib.NewKeyPair()
p.MyLookupKp = meowlib.NewKeyPair()
p.Contact.Name = "foo"
p.Contact.ContactPublicKey = p.MyLookupKp.Public
p.Contact.EncryptionPublicKey = p.MyIdentity.Public
p.Contact.LookupPublicKey = p.MyEncryptionKp.Public
p.Contact.AddUrls([]string{"http:/127.0.0.1/meow", "tcp://localhost:1234"})
id.Peers = append(id.Peers, p)
id := createId()
name := id.Peers[0].Name
assert.Equal(t, len(id.Peers), 1)
h := len(id.HiddenPeers)
id.HidePeer(0, "mypassword")
@ -60,5 +74,8 @@ func TestHidePeer(t *testing.T) {
assert.Equal(t, len(id.HiddenPeers), h+1)
id.TryUnlockHidden("mypassword")
assert.Equal(t, len(id.unlockedHiddenPeers), 1)
assert.Equal(t, id.unlockedHiddenPeers[0].Name, p.Name)
assert.Equal(t, id.unlockedHiddenPeers[0].Name, name)
if exists("test.id") {
os.Remove("test.id")
}
}