From 5228aef0889b8d750440bf274a1c7ef2c8b57fcb Mon Sep 17 00:00:00 2001 From: lash Date: Mon, 13 Jan 2025 21:33:25 +0000 Subject: [PATCH] Add mem storage service --- storage/parse.go | 3 ++- testutil/mocks/storage.go | 42 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 testutil/mocks/storage.go diff --git a/storage/parse.go b/storage/parse.go index 41dac6b..7fbded7 100644 --- a/storage/parse.go +++ b/storage/parse.go @@ -7,7 +7,8 @@ import ( ) const ( - DBTYPE_MEM = iota + DBTYPE_NONE = iota + DBTYPE_MEM DBTYPE_GDBM DBTYPE_POSTGRES ) diff --git a/testutil/mocks/storage.go b/testutil/mocks/storage.go new file mode 100644 index 0000000..003e48c --- /dev/null +++ b/testutil/mocks/storage.go @@ -0,0 +1,42 @@ +package mocks + +import ( + "context" + + "git.defalsify.org/vise.git/db" + memdb "git.defalsify.org/vise.git/db/mem" + "git.defalsify.org/vise.git/resource" + "git.defalsify.org/vise.git/persist" +) + +type MemStorageService struct { + Db db.Db + pe *persist.Persister + rs resource.Resource +} + +func NewMemStorageService(ctx context.Context) *MemStorageService { + svc := &MemStorageService{ + Db: memdb.NewMemDb(), + } + err := svc.Db.Connect(ctx, "") + if err != nil { + panic(err) + } + svc.pe = persist.NewPersister(svc.Db) + svc.rs = resource.NewMenuResource() + return svc +} + +func (mss *MemStorageService) GetPersister(ctx context.Context) (*persist.Persister, error) { + return mss.pe, nil +} + +func (mss *MemStorageService) GetUserdataDb(ctx context.Context) (db.Db, error) { + return mss.Db, nil +} + +func (mss *MemStorageService) GetResource(ctx context.Context) (resource.Resource, error) { + return mss.rs, nil +} +