remove redundant type check

info.itemType already looks through each service entry
to find the item type.  A service nil check is redundant.
Adds a qol func for asking if an itemInfo is a driveish item.
This commit is contained in:
ryanfkeepers 2023-09-06 14:40:31 -06:00
parent 59bf350603
commit 62ce55d742
3 changed files with 98 additions and 5 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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())
})
}
}