Consistent backup model types (#1513)

## Description

Make the return type of looking up backup models more consistent by always returning pointers to items. This helps avoid some type casting that could occur in some situations and makes the function definition for print more consistent because they will always work with a pointer type

## Type of change

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

## Issue(s)

* closes #1512 

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2022-11-16 16:55:03 -08:00 committed by GitHub
parent 80bbbdb87d
commit cca5759d7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 9 additions and 9 deletions

View File

@ -408,7 +408,7 @@ func (MockBackupGetter) Backup(
return nil, errors.New("unexpected call to mock") return nil, errors.New("unexpected call to mock")
} }
func (MockBackupGetter) Backups(context.Context, ...store.FilterOption) ([]backup.Backup, error) { func (MockBackupGetter) Backups(context.Context, ...store.FilterOption) ([]*backup.Backup, error) {
return nil, errors.New("unexpected call to mock") return nil, errors.New("unexpected call to mock")
} }

View File

@ -74,7 +74,7 @@ func (b Backup) Print(ctx context.Context) {
} }
// PrintAll writes the slice of Backups to StdOut, in the format requested by the caller. // PrintAll writes the slice of Backups to StdOut, in the format requested by the caller.
func PrintAll(ctx context.Context, bs []Backup) { func PrintAll(ctx context.Context, bs []*Backup) {
if len(bs) == 0 { if len(bs) == 0 {
print.Info(ctx, "No backups available") print.Info(ctx, "No backups available")
return return

View File

@ -27,7 +27,7 @@ var ErrorRepoAlreadyExists = errors.New("a repository was already initialized wi
// repository. // repository.
type BackupGetter interface { type BackupGetter interface {
Backup(ctx context.Context, id model.StableID) (*backup.Backup, error) Backup(ctx context.Context, id model.StableID) (*backup.Backup, error)
Backups(ctx context.Context, fs ...store.FilterOption) ([]backup.Backup, error) Backups(ctx context.Context, fs ...store.FilterOption) ([]*backup.Backup, error)
BackupDetails( BackupDetails(
ctx context.Context, ctx context.Context,
backupID string, backupID string,
@ -232,7 +232,7 @@ func (r repository) Backup(ctx context.Context, id model.StableID) (*backup.Back
} }
// backups lists backups in a repository // backups lists backups in a repository
func (r repository) Backups(ctx context.Context, fs ...store.FilterOption) ([]backup.Backup, error) { func (r repository) Backups(ctx context.Context, fs ...store.FilterOption) ([]*backup.Backup, error) {
sw := store.NewKopiaStore(r.modelStore) sw := store.NewKopiaStore(r.modelStore)
return sw.GetBackups(ctx, fs...) return sw.GetBackups(ctx, fs...)
} }

View File

@ -168,7 +168,7 @@ func runBackupListLoadTest(
t.Run("backup_list_"+name, func(t *testing.T) { t.Run("backup_list_"+name, func(t *testing.T) {
var ( var (
err error err error
bs []backup.Backup bs []*backup.Backup
labels = pprof.Labels("list_load_test", name) labels = pprof.Labels("list_load_test", name)
) )

View File

@ -54,7 +54,7 @@ func (w Wrapper) GetBackup(ctx context.Context, backupID model.StableID) (*backu
func (w Wrapper) GetBackups( func (w Wrapper) GetBackups(
ctx context.Context, ctx context.Context,
filters ...FilterOption, filters ...FilterOption,
) ([]backup.Backup, error) { ) ([]*backup.Backup, error) {
q := &queryFilters{} q := &queryFilters{}
q.populate(filters...) q.populate(filters...)
@ -63,12 +63,12 @@ func (w Wrapper) GetBackups(
return nil, err return nil, err
} }
bs := make([]backup.Backup, len(bms)) bs := make([]*backup.Backup, len(bms))
for i, bm := range bms { for i, bm := range bms {
b := backup.Backup{} b := &backup.Backup{}
err := w.GetWithModelStoreID(ctx, model.BackupSchema, bm.ModelStoreID, &b) err := w.GetWithModelStoreID(ctx, model.BackupSchema, bm.ModelStoreID, b)
if err != nil { if err != nil {
return nil, err return nil, err
} }