Create interface for Repository (#938)

## Description

Aid in testing. Break the interface in two for the moment, one of which is embedded in the other. The smaller interface focuses just on getting information about backups from the ModelStore.

## Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Test
- [ ] 💻 CI/Deployment
- [x] 🐹 Trivial/Minor

## Issue(s)

* #913 

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2022-09-22 15:09:16 -07:00 committed by GitHub
parent 3f3c8217a3
commit 8c674fa17b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 20 deletions

View File

@ -42,7 +42,7 @@ type BackupExchangeIntegrationSuite struct {
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
cfgFP string cfgFP string
repo *repository.Repository repo repository.Repository
m365UserID string m365UserID string
} }
@ -131,7 +131,7 @@ type PreparedBackupExchangeIntegrationSuite struct {
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
cfgFP string cfgFP string
repo *repository.Repository repo repository.Repository
m365UserID string m365UserID string
backupOps map[path.CategoryType]operations.BackupOperation backupOps map[path.CategoryType]operations.BackupOperation
} }
@ -303,7 +303,7 @@ type BackupDeleteExchangeIntegrationSuite struct {
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
cfgFP string cfgFP string
repo *repository.Repository repo repository.Repository
backupOp operations.BackupOperation backupOp operations.BackupOperation
} }

View File

@ -39,7 +39,7 @@ type RestoreExchangeIntegrationSuite struct {
st storage.Storage st storage.Storage
vpr *viper.Viper vpr *viper.Viper
cfgFP string cfgFP string
repo *repository.Repository repo repository.Repository
m365UserID string m365UserID string
backupOps map[path.CategoryType]operations.BackupOperation backupOps map[path.CategoryType]operations.BackupOperation
} }

View File

@ -28,7 +28,7 @@ func RequireProps(props map[string]string) error {
} }
// CloseRepo handles closing a repo. // CloseRepo handles closing a repo.
func CloseRepo(ctx context.Context, r *repository.Repository) { func CloseRepo(ctx context.Context, r repository.Repository) {
if err := r.Close(ctx); err != nil { if err := r.Close(ctx); err != nil {
fmt.Print("Error closing repository:", err) fmt.Print("Error closing repository:", err)
} }

View File

@ -20,8 +20,34 @@ import (
"github.com/alcionai/corso/src/pkg/store" "github.com/alcionai/corso/src/pkg/store"
) )
// BackupGetter deals with retrieving metadata about backups from the
// repository.
type BackupGetter interface {
Backup(ctx context.Context, id model.StableID) (*backup.Backup, error)
Backups(ctx context.Context) ([]backup.Backup, error)
BackupDetails(
ctx context.Context,
backupID string,
) (*details.Details, *backup.Backup, error)
}
type Repository interface {
Close(context.Context) error
NewBackup(
ctx context.Context,
self selectors.Selector,
) (operations.BackupOperation, error)
NewRestore(
ctx context.Context,
backupID string,
sel selectors.Selector,
) (operations.RestoreOperation, error)
DeleteBackup(ctx context.Context, id model.StableID) error
BackupGetter
}
// Repository contains storage provider information. // Repository contains storage provider information.
type Repository struct { type repository struct {
ID uuid.UUID ID uuid.UUID
CreatedAt time.Time CreatedAt time.Time
Version string // in case of future breaking changes Version string // in case of future breaking changes
@ -48,7 +74,7 @@ func Initialize(
acct account.Account, acct account.Account,
s storage.Storage, s storage.Storage,
opts control.Options, opts control.Options,
) (*Repository, error) { ) (Repository, error) {
kopiaRef := kopia.NewConn(s) kopiaRef := kopia.NewConn(s)
if err := kopiaRef.Initialize(ctx); err != nil { if err := kopiaRef.Initialize(ctx); err != nil {
return nil, err return nil, err
@ -67,7 +93,7 @@ func Initialize(
return nil, err return nil, err
} }
r := Repository{ r := repository{
ID: uuid.New(), ID: uuid.New(),
Version: "v1", Version: "v1",
Account: acct, Account: acct,
@ -92,7 +118,7 @@ func Connect(
acct account.Account, acct account.Account,
s storage.Storage, s storage.Storage,
opts control.Options, opts control.Options,
) (*Repository, error) { ) (Repository, error) {
kopiaRef := kopia.NewConn(s) kopiaRef := kopia.NewConn(s)
if err := kopiaRef.Connect(ctx); err != nil { if err := kopiaRef.Connect(ctx); err != nil {
return nil, err return nil, err
@ -112,7 +138,7 @@ func Connect(
} }
// todo: ID and CreatedAt should get retrieved from a stored kopia config. // todo: ID and CreatedAt should get retrieved from a stored kopia config.
r := Repository{ r := repository{
Version: "v1", Version: "v1",
Account: acct, Account: acct,
Storage: s, Storage: s,
@ -124,7 +150,7 @@ func Connect(
return &r, nil return &r, nil
} }
func (r *Repository) Close(ctx context.Context) error { func (r *repository) Close(ctx context.Context) error {
if err := r.Bus.Close(); err != nil { if err := r.Bus.Close(); err != nil {
logger.Ctx(ctx).Debugw("closing the event bus", "err", err) logger.Ctx(ctx).Debugw("closing the event bus", "err", err)
} }
@ -149,7 +175,7 @@ func (r *Repository) Close(ctx context.Context) error {
} }
// NewBackup generates a BackupOperation runner. // NewBackup generates a BackupOperation runner.
func (r Repository) NewBackup( func (r repository) NewBackup(
ctx context.Context, ctx context.Context,
selector selectors.Selector, selector selectors.Selector,
) (operations.BackupOperation, error) { ) (operations.BackupOperation, error) {
@ -164,7 +190,7 @@ func (r Repository) NewBackup(
} }
// NewRestore generates a restoreOperation runner. // NewRestore generates a restoreOperation runner.
func (r Repository) NewRestore( func (r repository) NewRestore(
ctx context.Context, ctx context.Context,
backupID string, backupID string,
sel selectors.Selector, sel selectors.Selector,
@ -181,25 +207,25 @@ func (r Repository) NewRestore(
} }
// backups lists a backup by id // backups lists a backup by id
func (r Repository) Backup(ctx context.Context, id model.StableID) (*backup.Backup, error) { func (r repository) Backup(ctx context.Context, id model.StableID) (*backup.Backup, error) {
sw := store.NewKopiaStore(r.modelStore) sw := store.NewKopiaStore(r.modelStore)
return sw.GetBackup(ctx, id) return sw.GetBackup(ctx, id)
} }
// backups lists backups in a repository // backups lists backups in a repository
func (r Repository) Backups(ctx context.Context) ([]backup.Backup, error) { func (r repository) Backups(ctx context.Context) ([]backup.Backup, error) {
sw := store.NewKopiaStore(r.modelStore) sw := store.NewKopiaStore(r.modelStore)
return sw.GetBackups(ctx) return sw.GetBackups(ctx)
} }
// BackupDetails returns the specified backup details object // BackupDetails returns the specified backup details object
func (r Repository) BackupDetails(ctx context.Context, backupID string) (*details.Details, *backup.Backup, error) { func (r repository) BackupDetails(ctx context.Context, backupID string) (*details.Details, *backup.Backup, error) {
sw := store.NewKopiaStore(r.modelStore) sw := store.NewKopiaStore(r.modelStore)
return sw.GetDetailsFromBackupID(ctx, model.StableID(backupID)) return sw.GetDetailsFromBackupID(ctx, model.StableID(backupID))
} }
// DeleteBackup removes the backup from both the model store and the backup storage. // DeleteBackup removes the backup from both the model store and the backup storage.
func (r Repository) DeleteBackup(ctx context.Context, id model.StableID) error { func (r repository) DeleteBackup(ctx context.Context, id model.StableID) error {
bu, err := r.Backup(ctx, id) bu, err := r.Backup(ctx, id)
if err != nil { if err != nil {
return err return err

View File

@ -16,7 +16,7 @@ import (
) )
func initM365Repo(t *testing.T) ( func initM365Repo(t *testing.T) (
context.Context, *repository.Repository, account.Account, storage.Storage, context.Context, repository.Repository, account.Account, storage.Storage,
) { ) {
_, err := tester.GetRequiredEnvSls( _, err := tester.GetRequiredEnvSls(
tester.AWSStorageCredEnvs, tester.AWSStorageCredEnvs,
@ -45,7 +45,7 @@ func initM365Repo(t *testing.T) (
type RepositoryLoadTestExchangeSuite struct { type RepositoryLoadTestExchangeSuite struct {
suite.Suite suite.Suite
ctx context.Context ctx context.Context
repo *repository.Repository repo repository.Repository
acct account.Account acct account.Account
st storage.Storage st storage.Storage
} }
@ -99,7 +99,7 @@ func (suite *RepositoryLoadTestExchangeSuite) TestExchange() {
type RepositoryLoadTestOneDriveSuite struct { type RepositoryLoadTestOneDriveSuite struct {
suite.Suite suite.Suite
ctx context.Context ctx context.Context
repo *repository.Repository repo repository.Repository
acct account.Account acct account.Account
st storage.Storage st storage.Storage
} }