From 698740e20a994c31bf32834e56a1fdac9fae85ac Mon Sep 17 00:00:00 2001 From: ycc Date: Fri, 17 Feb 2023 22:30:13 +0100 Subject: [PATCH] Identity accessors --- client/config.go | 14 +++++++++++--- client/storage_test.go | 32 +++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/client/config.go b/client/config.go index 57f7279..02d3a03 100644 --- a/client/config.go +++ b/client/config.go @@ -35,9 +35,9 @@ type Config struct { DbSuffix string `json:"db_suffix,omitempty"` // Inner - memoryPassword string `json:"memory_password,omitempty"` - additionalPasswords []string `json:"additional_passwords,omitempty"` - me *Identity `json:"me,omitempty"` + memoryPassword string + additionalPasswords []string + me *Identity } var instance *Config @@ -82,6 +82,14 @@ func (c *Config) GetMemPass() string { return c.memoryPassword } +func (c *Config) GetIdentity() *Identity { + return c.me +} + +func (c *Config) SetIdentity(id *Identity) { + c.me = id +} + func (c *Config) SaveIdentity() error { return c.me.Save() } diff --git a/client/storage_test.go b/client/storage_test.go index 9112a62..b094ab3 100644 --- a/client/storage_test.go +++ b/client/storage_test.go @@ -38,9 +38,35 @@ func TestStoreMessage(t *testing.T) { panic(err) } } - } -func TestGetLastMessages(t *testing.T) { - +func TestManyStoreMessage(t *testing.T) { + id := createId() + for i := 1; i < 100; i++ { + var um meowlib.UserMessage + um.Data = []byte(randomLenString(20, 200)) + err := StoreMessage(&id.Peers[0], &um, GetConfig().memoryPassword) + if err != nil { + log.Fatal(err) + } + } + messages, err := GetLastMessages(&id.Peers[0], 0, 0, 10, GetConfig().memoryPassword) + if err != nil { + log.Fatal(err) + } + // Checks + assert.Equal(t, len(messages), 10, "not 10 message") + // Cleanup + if exists("test.id") { + os.Remove("test.id") + } + files, err := filepath.Glob("*.sqlite") + if err != nil { + panic(err) + } + for _, f := range files { + if err := os.Remove(f); err != nil { + panic(err) + } + } }