diff --git a/src/pkg/backup/details/details.go b/src/pkg/backup/details/details.go index 4d224f475..ab2b57191 100644 --- a/src/pkg/backup/details/details.go +++ b/src/pkg/backup/details/details.go @@ -46,11 +46,7 @@ func (d *Details) add( // Use the item name and the path for the ShortRef. This ensures that renames // within a directory generate unique ShortRefs. - if info.infoType() == OneDriveItem || info.infoType() == SharePointLibrary { - if info.OneDrive == nil && info.SharePoint == nil { - return entry, clues.New("item is not SharePoint or OneDrive type") - } - + if info.isDriveItem() { // clean metadata suffixes from item refs entry.ItemRef = withoutMetadataSuffix(entry.ItemRef) } diff --git a/src/pkg/backup/details/iteminfo.go b/src/pkg/backup/details/iteminfo.go index 25a77d5c2..180572db3 100644 --- a/src/pkg/backup/details/iteminfo.go +++ b/src/pkg/backup/details/iteminfo.go @@ -182,3 +182,14 @@ func (i ItemInfo) updateFolder(f *FolderInfo) error { return clues.New("unsupported type") } } + +// true if the info represents an item backed by the drive api. +func (i ItemInfo) isDriveItem() bool { + iit := i.infoType() + + if !(iit == OneDriveItem || iit == SharePointLibrary) { + return false + } + + return !(i.OneDrive == nil && i.SharePoint == nil && i.Groups == nil) +} diff --git a/src/pkg/backup/details/iteminfo_test.go b/src/pkg/backup/details/iteminfo_test.go new file mode 100644 index 000000000..1073edb27 --- /dev/null +++ b/src/pkg/backup/details/iteminfo_test.go @@ -0,0 +1,86 @@ +package details + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" + + "github.com/alcionai/corso/src/internal/tester" +) + +type ItemInfoUnitSuite struct { + tester.Suite +} + +func TestItemInfoUnitSuite(t *testing.T) { + suite.Run(t, &ItemInfoUnitSuite{Suite: tester.NewUnitSuite(t)}) +} + +func (suite *ItemInfoUnitSuite) TestItemInfo_IsDriveItem() { + table := []struct { + name string + ii ItemInfo + expect assert.BoolAssertionFunc + }{ + { + name: "onedrive item", + ii: ItemInfo{ + OneDrive: &OneDriveInfo{ + ItemType: OneDriveItem, + }, + }, + expect: assert.True, + }, + { + name: "sharepoint library", + ii: ItemInfo{ + SharePoint: &SharePointInfo{ + ItemType: SharePointLibrary, + }, + }, + expect: assert.True, + }, + { + name: "sharepoint page", + ii: ItemInfo{ + SharePoint: &SharePointInfo{ + ItemType: SharePointPage, + }, + }, + expect: assert.False, + }, + { + name: "groups library", + ii: ItemInfo{ + Groups: &GroupsInfo{ + ItemType: SharePointLibrary, + }, + }, + expect: assert.True, + }, + { + name: "groups channel message", + ii: ItemInfo{ + Groups: &GroupsInfo{ + ItemType: GroupsChannelMessage, + }, + }, + expect: assert.False, + }, + { + name: "exchange anything", + ii: ItemInfo{ + Groups: &GroupsInfo{ + ItemType: ExchangeMail, + }, + }, + expect: assert.False, + }, + } + for _, test := range table { + suite.Run(test.name, func() { + test.expect(suite.T(), test.ii.isDriveItem()) + }) + } +}