Add mem storage service

This commit is contained in:
lash 2025-01-13 21:33:25 +00:00
parent 5bf0a0e858
commit 5228aef088
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 44 additions and 1 deletions

View File

@ -7,7 +7,8 @@ import (
)
const (
DBTYPE_MEM = iota
DBTYPE_NONE = iota
DBTYPE_MEM
DBTYPE_GDBM
DBTYPE_POSTGRES
)

42
testutil/mocks/storage.go Normal file
View File

@ -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
}