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

View File

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