mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Make integration test compile
This commit is contained in:
parent
abd98768e8
commit
f30ab827d2
5 changed files with 97 additions and 18 deletions
69
commonspace/storageutils_test.go
Normal file
69
commonspace/storageutils_test.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
package commonspace
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
anystore "github.com/anyproto/any-store"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/anyproto/any-sync/app"
|
||||
"github.com/anyproto/any-sync/commonspace/spacestorage"
|
||||
)
|
||||
|
||||
type spaceStorageProvider struct {
|
||||
rootPath string
|
||||
}
|
||||
|
||||
func (s *spaceStorageProvider) Run(ctx context.Context) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *spaceStorageProvider) Close(ctx context.Context) (err error) {
|
||||
return unix.Rmdir(s.rootPath)
|
||||
}
|
||||
|
||||
func (s *spaceStorageProvider) Init(a *app.App) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *spaceStorageProvider) Name() (name string) {
|
||||
return spacestorage.CName
|
||||
}
|
||||
|
||||
func (s *spaceStorageProvider) WaitSpaceStorage(ctx context.Context, id string) (spacestorage.SpaceStorage, error) {
|
||||
dbPath := path.Join(s.rootPath, id)
|
||||
if _, err := os.Stat(dbPath); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
db, err := anystore.Open(ctx, dbPath, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return spacestorage.New(id, db), nil
|
||||
}
|
||||
|
||||
func (s *spaceStorageProvider) SpaceExists(id string) bool {
|
||||
if id == "" {
|
||||
return false
|
||||
}
|
||||
dbPath := path.Join(s.rootPath, id)
|
||||
if _, err := os.Stat(dbPath); err != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *spaceStorageProvider) CreateSpaceStorage(ctx context.Context, payload spacestorage.SpaceStorageCreatePayload) (spacestorage.SpaceStorage, error) {
|
||||
id := payload.SpaceHeaderWithId.Id
|
||||
if s.SpaceExists(id) {
|
||||
return nil, spacestorage.ErrSpaceStorageExists
|
||||
}
|
||||
dbPath := path.Join(s.rootPath, id)
|
||||
db, err := anystore.Open(ctx, dbPath, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return spacestorage.Create(ctx, db, payload)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue