display the backup owner name when listing

This commit is contained in:
ryanfkeepers 2023-03-30 13:33:50 -06:00
parent ca2fbda260
commit b00559acc8
2 changed files with 47 additions and 24 deletions

View File

@ -165,6 +165,11 @@ type Printable struct {
// MinimumPrintable reduces the Backup to its minimally printable details.
func (b Backup) MinimumPrintable() any {
name := b.ResourceOwnerName
if len(name) == 0 {
name = b.Selector.Name()
}
return Printable{
ID: b.ID,
ErrorCount: b.ErrorCount,
@ -173,7 +178,7 @@ func (b Backup) MinimumPrintable() any {
Version: "0",
BytesRead: b.BytesRead,
BytesUploaded: b.BytesUploaded,
Owner: b.Selector.DiscreteOwner,
Owner: name,
}
}
@ -232,10 +237,15 @@ func (b Backup) Values() []string {
status += (")")
}
name := b.ResourceOwnerName
if len(name) == 0 {
name = b.Selector.Name()
}
return []string{
common.FormatTabularDisplayTime(b.StartedAt),
string(b.ID),
status,
b.Selector.DiscreteOwner,
name,
}
}

View File

@ -24,8 +24,10 @@ func TestBackupUnitSuite(t *testing.T) {
suite.Run(t, &BackupUnitSuite{Suite: tester.NewUnitSuite(t)})
}
const testDomainOwner = "test-domain-owner"
func stubBackup(t time.Time) backup.Backup {
sel := selectors.NewExchangeBackup([]string{"test"})
sel := selectors.NewExchangeBackup([]string{testDomainOwner})
sel.Include(sel.AllData())
return backup.Backup{
@ -61,30 +63,41 @@ func stubBackup(t time.Time) backup.Backup {
func (suite *BackupUnitSuite) TestBackup_HeadersValues() {
var (
t = suite.T()
now = time.Now()
b = stubBackup(now)
expectHs = []string{
"Started At",
"ID",
"Status",
"Resource Owner",
}
nowFmt = common.FormatTabularDisplayTime(now)
expectVs = []string{
nowFmt,
"id",
"status (2 errors, 1 skipped: 1 malware)",
"test",
}
now = time.Now()
nowFmt = common.FormatTabularDisplayTime(now)
expectHs = []string{"Started At", "ID", "Status", "Resource Owner"}
expectVsBase = []string{nowFmt, "id", "status (2 errors, 1 skipped: 1 malware)"}
)
// single skipped malware
hs := b.Headers()
assert.Equal(t, expectHs, hs)
table := []struct {
name string
bup func() backup.Backup
expectVs []string
}{
{
name: "owner from selectors",
bup: func() backup.Backup { return stubBackup(now) },
expectVs: append(expectVsBase, testDomainOwner),
},
{
name: "owner from backup",
bup: func() backup.Backup {
b := stubBackup(now)
b.ResourceOwnerName = "test ro name"
return b
},
expectVs: append(expectVsBase, "test ro name"),
},
}
for _, test := range table {
suite.Run(test.name, func() {
t := suite.T()
b := test.bup()
vs := b.Values()
assert.Equal(t, expectVs, vs)
assert.Equal(t, expectHs, b.Headers()) // not elementsMatch, order matters
assert.Equal(t, test.expectVs, b.Values()) // not elementsMatch, order matters
})
}
}
func (suite *BackupUnitSuite) TestBackup_Values_statusVariations() {