Show backup size for list commands (#1648)

## Description

Add size and stored size to cli output for `backup list`

## Type of change

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

## Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* fixes https://github.com/alcionai/corso/issues/1622

## Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abin Simon 2022-12-02 11:28:23 +05:30 committed by GitHub
parent 3eae0f969d
commit d11183658a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 14 deletions

View File

@ -89,23 +89,27 @@ func PrintAll(ctx context.Context, bs []*Backup) {
} }
type Printable struct { type Printable struct {
ID model.StableID `json:"id"` ID model.StableID `json:"id"`
ErrorCount int `json:"errorCount"` ErrorCount int `json:"errorCount"`
StartedAt time.Time `json:"started at"` StartedAt time.Time `json:"started at"`
Status string `json:"status"` Status string `json:"status"`
Version string `json:"version"` Version string `json:"version"`
Selectors selectors.Printable `json:"selectors"` Selectors selectors.Printable `json:"selectors"`
BytesRead int64 `json:"bytesRead"`
BytesUploaded int64 `json:"bytesUploaded"`
} }
// MinimumPrintable reduces the Backup to its minimally printable details. // MinimumPrintable reduces the Backup to its minimally printable details.
func (b Backup) MinimumPrintable() any { func (b Backup) MinimumPrintable() any {
return Printable{ return Printable{
ID: b.ID, ID: b.ID,
ErrorCount: support.GetNumberOfErrors(b.ReadErrors) + support.GetNumberOfErrors(b.WriteErrors), ErrorCount: support.GetNumberOfErrors(b.ReadErrors) + support.GetNumberOfErrors(b.WriteErrors),
StartedAt: b.StartedAt, StartedAt: b.StartedAt,
Status: b.Status, Status: b.Status,
Version: "0", Version: "0",
Selectors: b.Selectors.ToPrintable(), Selectors: b.Selectors.ToPrintable(),
BytesRead: b.BytesRead,
BytesUploaded: b.BytesUploaded,
} }
} }

View File

@ -45,8 +45,10 @@ func stubBackup(t time.Time) backup.Backup {
WriteErrors: errors.New("1"), WriteErrors: errors.New("1"),
}, },
ReadWrites: stats.ReadWrites{ ReadWrites: stats.ReadWrites{
ItemsRead: 1, BytesRead: 301,
ItemsWritten: 1, BytesUploaded: 301,
ItemsRead: 1,
ItemsWritten: 1,
}, },
StartAndEndTime: stats.StartAndEndTime{ StartAndEndTime: stats.StartAndEndTime{
StartedAt: t, StartedAt: t,
@ -98,4 +100,7 @@ func (suite *BackupSuite) TestBackup_MinimumPrintable() {
bselp := b.Selectors.ToPrintable() bselp := b.Selectors.ToPrintable()
assert.Equal(t, bselp, result.Selectors, "selectors") assert.Equal(t, bselp, result.Selectors, "selectors")
assert.Equal(t, bselp.Resources(), result.Selectors.Resources(), "selector resources") assert.Equal(t, bselp.Resources(), result.Selectors.Resources(), "selector resources")
assert.Equal(t, b.BytesRead, result.BytesRead, "size")
assert.Equal(t, b.BytesUploaded, result.BytesUploaded, "stored size")
} }