corso/src/pkg/backup/backup_test.go
Keepers 6224a92e7a
filter backup details by flags (#371)
* filter backup details by flags

`backup details` should have its output filtered by the flags provided by
the user.  In addition, the selector's FilterDetails should maintain
information (esp service info) about the entries, rather than slicing them
down to only the path reference.
2022-07-20 16:25:28 -06:00

148 lines
2.8 KiB
Go

package backup_test
import (
"testing"
"time"
"github.com/stretchr/testify/suite"
"github.com/zeebo/assert"
"github.com/alcionai/corso/internal/model"
"github.com/alcionai/corso/pkg/backup"
)
type BackupSuite struct {
suite.Suite
}
func TestBackupSuite(t *testing.T) {
suite.Run(t, new(BackupSuite))
}
func (suite *BackupSuite) TestBackup_HeadersValues() {
t := suite.T()
now := time.Now()
b := backup.Backup{
BaseModel: model.BaseModel{
StableID: model.ID("stable"),
},
CreationTime: now,
SnapshotID: "snapshot",
DetailsID: "details",
}
expectHs := []string{
"Creation Time",
"Stable ID",
"Snapshot ID",
"Details ID",
}
hs := b.Headers()
assert.DeepEqual(t, expectHs, hs)
expectVs := []string{
now.Format(time.RFC3339Nano),
"stable",
"snapshot",
"details",
}
vs := b.Values()
assert.DeepEqual(t, expectVs, vs)
}
func (suite *BackupSuite) TestDetailsEntry_HeadersValues() {
now := time.Now()
nowStr := now.Format(time.RFC3339Nano)
table := []struct {
name string
entry backup.DetailsEntry
expectHs []string
expectVs []string
}{
{
name: "no info",
entry: backup.DetailsEntry{
RepoRef: "reporef",
},
expectHs: []string{"Repo Ref"},
expectVs: []string{"reporef"},
},
{
name: "exhange info",
entry: backup.DetailsEntry{
RepoRef: "reporef",
ItemInfo: backup.ItemInfo{
Exchange: &backup.ExchangeInfo{
Sender: "sender",
Subject: "subject",
Received: now,
},
},
},
expectHs: []string{"Repo Ref", "Sender", "Subject", "Received"},
expectVs: []string{"reporef", "sender", "subject", nowStr},
},
{
name: "sharepoint info",
entry: backup.DetailsEntry{
RepoRef: "reporef",
ItemInfo: backup.ItemInfo{
Sharepoint: &backup.SharepointInfo{},
},
},
expectHs: []string{"Repo Ref"},
expectVs: []string{"reporef"},
},
}
for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) {
hs := test.entry.Headers()
assert.DeepEqual(t, test.expectHs, hs)
vs := test.entry.Values()
assert.DeepEqual(t, test.expectVs, vs)
})
}
}
func (suite *BackupSuite) TestDetailsModel_Path() {
table := []struct {
name string
ents []backup.DetailsEntry
expect []string
}{
{
name: "nil entries",
ents: nil,
expect: []string{},
},
{
name: "single entry",
ents: []backup.DetailsEntry{
{RepoRef: "abcde"},
},
expect: []string{"abcde"},
},
{
name: "multiple entries",
ents: []backup.DetailsEntry{
{RepoRef: "abcde"},
{RepoRef: "12345"},
},
expect: []string{"abcde", "12345"},
},
}
for _, test := range table {
suite.T().Run(test.name, func(t *testing.T) {
d := backup.Details{
DetailsModel: backup.DetailsModel{
Entries: test.ents,
},
}
assert.DeepEqual(t, test.expect, d.Paths())
})
}
}