Don't use RepoRef in selector reduction (#3236)

A few high-level things of note:
* things will no longer match on folder ID. Folder IDs weren't displayed
  to the user via CLI and SDK consumers have no insight into folder IDs
  so this shouldn't be an issue
* OneDrive and SharePoint match on ParentPath (derived from
  LocationRef). ParentPath *does not* include root: in the path

Not matching on folder ID should be the only user-visible change in
this PR

First commit contains the required logic changes. All other changes
are test updates

---

#### Does this PR need a docs update or release note?

- [ ]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [x]  No

#### Type of change

- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [x] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup

#### Issue(s)

* closes #3194

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-04-27 15:01:34 -07:00 committed by GitHub
parent 1cd592d216
commit 754e14d7a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 467 additions and 266 deletions

View File

@ -138,14 +138,14 @@ var (
Name: "EmailsFolderPrefixMatch", Name: "EmailsFolderPrefixMatch",
Expected: testdata.ExchangeEmailItems, Expected: testdata.ExchangeEmailItems,
Opts: utils.ExchangeOpts{ Opts: utils.ExchangeOpts{
EmailFolder: []string{testdata.ExchangeEmailInboxPath.Folder(false)}, EmailFolder: []string{testdata.ExchangeEmailInboxPath.FolderLocation()},
}, },
}, },
{ {
Name: "EmailsFolderPrefixMatchTrailingSlash", Name: "EmailsFolderPrefixMatchTrailingSlash",
Expected: testdata.ExchangeEmailItems, Expected: testdata.ExchangeEmailItems,
Opts: utils.ExchangeOpts{ Opts: utils.ExchangeOpts{
EmailFolder: []string{testdata.ExchangeEmailInboxPath.Folder(false) + "/"}, EmailFolder: []string{testdata.ExchangeEmailInboxPath.FolderLocation() + "/"},
}, },
}, },
{ {
@ -155,7 +155,7 @@ var (
testdata.ExchangeEmailItems[2], testdata.ExchangeEmailItems[2],
}, },
Opts: utils.ExchangeOpts{ Opts: utils.ExchangeOpts{
EmailFolder: []string{testdata.ExchangeEmailBasePath2.Folder(false)}, EmailFolder: []string{testdata.ExchangeEmailBasePath2.FolderLocation()},
}, },
}, },
{ {
@ -165,7 +165,7 @@ var (
testdata.ExchangeEmailItems[2], testdata.ExchangeEmailItems[2],
}, },
Opts: utils.ExchangeOpts{ Opts: utils.ExchangeOpts{
EmailFolder: []string{testdata.ExchangeEmailBasePath2.Folder(false) + "/"}, EmailFolder: []string{testdata.ExchangeEmailBasePath2.FolderLocation() + "/"},
}, },
}, },
{ {
@ -209,7 +209,7 @@ var (
Name: "MailShortRef", Name: "MailShortRef",
Expected: []details.DetailsEntry{testdata.ExchangeEmailItems[0]}, Expected: []details.DetailsEntry{testdata.ExchangeEmailItems[0]},
Opts: utils.ExchangeOpts{ Opts: utils.ExchangeOpts{
Email: []string{testdata.ExchangeEmailItemPath1.ShortRef()}, Email: []string{testdata.ExchangeEmailItemPath1.RR.ShortRef()},
}, },
}, },
{ {
@ -220,8 +220,8 @@ var (
}, },
Opts: utils.ExchangeOpts{ Opts: utils.ExchangeOpts{
Email: []string{ Email: []string{
testdata.ExchangeEmailItemPath1.ShortRef(), testdata.ExchangeEmailItemPath1.RR.ShortRef(),
testdata.ExchangeEmailItemPath2.ShortRef(), testdata.ExchangeEmailItemPath2.RR.ShortRef(),
}, },
}, },
}, },
@ -248,8 +248,8 @@ var (
testdata.ExchangeEventsItems[0], testdata.ExchangeEventsItems[0],
}, },
Opts: utils.ExchangeOpts{ Opts: utils.ExchangeOpts{
Email: []string{testdata.ExchangeEmailItemPath1.ShortRef()}, Email: []string{testdata.ExchangeEmailItemPath1.RR.ShortRef()},
Event: []string{testdata.ExchangeEventsItemPath1.ShortRef()}, Event: []string{testdata.ExchangeEventsItemPath1.RR.ShortRef()},
}, },
}, },
} }
@ -375,6 +375,13 @@ var (
FolderPath: []string{testdata.OneDriveFolderFolder + "/"}, FolderPath: []string{testdata.OneDriveFolderFolder + "/"},
}, },
}, },
{
Name: "FolderRepoRefMatchesNothing",
Expected: []details.DetailsEntry{},
Opts: utils.OneDriveOpts{
FolderPath: []string{testdata.OneDriveFolderPath.RR.Folder(true)},
},
},
{ {
Name: "ShortRef", Name: "ShortRef",
Expected: []details.DetailsEntry{ Expected: []details.DetailsEntry{
@ -494,6 +501,13 @@ var (
FolderPath: []string{testdata.SharePointLibraryFolder + "/"}, FolderPath: []string{testdata.SharePointLibraryFolder + "/"},
}, },
}, },
{
Name: "FolderRepoRefMatchesNothing",
Expected: []details.DetailsEntry{},
Opts: utils.SharePointOpts{
FolderPath: []string{testdata.SharePointLibraryPath.RR.Folder(true)},
},
},
{ {
Name: "ShortRef", Name: "ShortRef",
Expected: []details.DetailsEntry{ Expected: []details.DetailsEntry{

View File

@ -1,7 +1,7 @@
package testdata package testdata
import ( import (
stdpath "path" "strings"
"time" "time"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
@ -33,7 +33,97 @@ func mustAppendPath(p path.Path, newElement string, isItem bool) path.Path {
return newP return newP
} }
func locFromRepo(rr path.Path, isItem bool) *path.Builder {
loc := &path.Builder{}
for _, e := range rr.Folders() {
loc = loc.Append(strings.TrimSuffix(e, folderSuffix))
}
if rr.Service() == path.OneDriveService || rr.Category() == path.LibrariesCategory {
loc = loc.PopFront()
}
// Folders don't have their final element in the location.
if !isItem {
loc = loc.Dir()
}
return loc
}
type repoRefAndLocRef struct {
RR path.Path
loc *path.Builder
}
func (p repoRefAndLocRef) mustAppend(newElement string, isItem bool) repoRefAndLocRef {
e := newElement + folderSuffix
if isItem {
e = newElement + fileSuffix
}
res := repoRefAndLocRef{
RR: mustAppendPath(p.RR, e, isItem),
}
res.loc = locFromRepo(res.RR, isItem)
return res
}
func (p repoRefAndLocRef) ItemLocation() string {
return strings.TrimSuffix(p.RR.Item(), fileSuffix)
}
func (p repoRefAndLocRef) FolderLocation() string {
lastElem := p.RR.ToBuilder().LastElem()
if len(p.RR.Item()) > 0 {
f := p.RR.Folders()
lastElem = f[len(f)-2]
}
return p.loc.Append(strings.TrimSuffix(lastElem, folderSuffix)).String()
}
func mustPathRep(ref string, isItem bool) repoRefAndLocRef {
res := repoRefAndLocRef{}
tmp := mustParsePath(ref, isItem)
// Now append stuff to the RepoRef elements so we have distinct LocationRef
// and RepoRef elements to simulate using IDs in the path instead of display
// names.
rrPB := &path.Builder{}
for _, e := range tmp.Folders() {
rrPB = rrPB.Append(e + folderSuffix)
}
if isItem {
rrPB = rrPB.Append(tmp.Item() + fileSuffix)
}
rr, err := rrPB.ToDataLayerPath(
tmp.Tenant(),
tmp.ResourceOwner(),
tmp.Service(),
tmp.Category(),
isItem)
if err != nil {
panic(err)
}
res.RR = rr
res.loc = locFromRepo(rr, isItem)
return res
}
const ( const (
folderSuffix = ".d"
fileSuffix = ".f"
ItemName1 = "item1" ItemName1 = "item1"
ItemName2 = "item2" ItemName2 = "item2"
ItemName3 = "item3" ItemName3 = "item3"
@ -47,20 +137,21 @@ var (
Time3 = time.Date(2023, 9, 21, 10, 0, 0, 0, time.UTC) Time3 = time.Date(2023, 9, 21, 10, 0, 0, 0, time.UTC)
Time4 = time.Date(2023, 10, 21, 10, 0, 0, 0, time.UTC) Time4 = time.Date(2023, 10, 21, 10, 0, 0, 0, time.UTC)
ExchangeEmailInboxPath = mustParsePath("tenant-id/exchange/user-id/email/Inbox", false) ExchangeEmailInboxPath = mustPathRep("tenant-id/exchange/user-id/email/Inbox", false)
ExchangeEmailBasePath = mustAppendPath(ExchangeEmailInboxPath, "subfolder", false) ExchangeEmailBasePath = ExchangeEmailInboxPath.mustAppend("subfolder", false)
ExchangeEmailBasePath2 = mustAppendPath(ExchangeEmailInboxPath, "othersubfolder/", false) ExchangeEmailBasePath2 = ExchangeEmailInboxPath.mustAppend("othersubfolder/", false)
ExchangeEmailBasePath3 = mustAppendPath(ExchangeEmailBasePath2, "subsubfolder", false) ExchangeEmailBasePath3 = ExchangeEmailBasePath2.mustAppend("subsubfolder", false)
ExchangeEmailItemPath1 = mustAppendPath(ExchangeEmailBasePath, ItemName1, true) ExchangeEmailItemPath1 = ExchangeEmailBasePath.mustAppend(ItemName1, true)
ExchangeEmailItemPath2 = mustAppendPath(ExchangeEmailBasePath2, ItemName2, true) ExchangeEmailItemPath2 = ExchangeEmailBasePath2.mustAppend(ItemName2, true)
ExchangeEmailItemPath3 = mustAppendPath(ExchangeEmailBasePath3, ItemName3, true) ExchangeEmailItemPath3 = ExchangeEmailBasePath3.mustAppend(ItemName3, true)
ExchangeEmailItems = []details.DetailsEntry{ ExchangeEmailItems = []details.DetailsEntry{
{ {
RepoRef: ExchangeEmailItemPath1.String(), RepoRef: ExchangeEmailItemPath1.RR.String(),
ShortRef: ExchangeEmailItemPath1.ShortRef(), ShortRef: ExchangeEmailItemPath1.RR.ShortRef(),
ParentRef: ExchangeEmailItemPath1.ToBuilder().Dir().ShortRef(), ParentRef: ExchangeEmailItemPath1.RR.ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath1.Item(), ItemRef: ExchangeEmailItemPath1.ItemLocation(),
LocationRef: ExchangeEmailItemPath1.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{ Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail, ItemType: details.ExchangeMail,
@ -71,10 +162,11 @@ var (
}, },
}, },
{ {
RepoRef: ExchangeEmailItemPath2.String(), RepoRef: ExchangeEmailItemPath2.RR.String(),
ShortRef: ExchangeEmailItemPath2.ShortRef(), ShortRef: ExchangeEmailItemPath2.RR.ShortRef(),
ParentRef: ExchangeEmailItemPath2.ToBuilder().Dir().ShortRef(), ParentRef: ExchangeEmailItemPath2.RR.ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath2.Item(), ItemRef: ExchangeEmailItemPath2.ItemLocation(),
LocationRef: ExchangeEmailItemPath2.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{ Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail, ItemType: details.ExchangeMail,
@ -85,10 +177,11 @@ var (
}, },
}, },
{ {
RepoRef: ExchangeEmailItemPath3.String(), RepoRef: ExchangeEmailItemPath3.RR.String(),
ShortRef: ExchangeEmailItemPath3.ShortRef(), ShortRef: ExchangeEmailItemPath3.RR.ShortRef(),
ParentRef: ExchangeEmailItemPath3.ToBuilder().Dir().ShortRef(), ParentRef: ExchangeEmailItemPath3.RR.ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath3.Item(), ItemRef: ExchangeEmailItemPath3.ItemLocation(),
LocationRef: ExchangeEmailItemPath3.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{ Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail, ItemType: details.ExchangeMail,
@ -100,18 +193,19 @@ var (
}, },
} }
ExchangeContactsRootPath = mustParsePath("tenant-id/exchange/user-id/contacts/contacts", false) ExchangeContactsRootPath = mustPathRep("tenant-id/exchange/user-id/contacts/contacts", false)
ExchangeContactsBasePath = mustAppendPath(ExchangeContactsRootPath, "contacts", false) ExchangeContactsBasePath = ExchangeContactsRootPath.mustAppend("contacts", false)
ExchangeContactsBasePath2 = mustAppendPath(ExchangeContactsRootPath, "morecontacts", false) ExchangeContactsBasePath2 = ExchangeContactsRootPath.mustAppend("morecontacts", false)
ExchangeContactsItemPath1 = mustAppendPath(ExchangeContactsBasePath, ItemName1, true) ExchangeContactsItemPath1 = ExchangeContactsBasePath.mustAppend(ItemName1, true)
ExchangeContactsItemPath2 = mustAppendPath(ExchangeContactsBasePath2, ItemName2, true) ExchangeContactsItemPath2 = ExchangeContactsBasePath2.mustAppend(ItemName2, true)
ExchangeContactsItems = []details.DetailsEntry{ ExchangeContactsItems = []details.DetailsEntry{
{ {
RepoRef: ExchangeContactsItemPath1.String(), RepoRef: ExchangeContactsItemPath1.RR.String(),
ShortRef: ExchangeContactsItemPath1.ShortRef(), ShortRef: ExchangeContactsItemPath1.RR.ShortRef(),
ParentRef: ExchangeContactsItemPath1.ToBuilder().Dir().ShortRef(), ParentRef: ExchangeContactsItemPath1.RR.ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath1.Item(), ItemRef: ExchangeContactsItemPath1.ItemLocation(),
LocationRef: ExchangeContactsItemPath1.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{ Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeContact, ItemType: details.ExchangeContact,
@ -120,10 +214,11 @@ var (
}, },
}, },
{ {
RepoRef: ExchangeContactsItemPath2.String(), RepoRef: ExchangeContactsItemPath2.RR.String(),
ShortRef: ExchangeContactsItemPath2.ShortRef(), ShortRef: ExchangeContactsItemPath2.RR.ShortRef(),
ParentRef: ExchangeContactsItemPath2.ToBuilder().Dir().ShortRef(), ParentRef: ExchangeContactsItemPath2.RR.ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath2.Item(), ItemRef: ExchangeContactsItemPath2.ItemLocation(),
LocationRef: ExchangeContactsItemPath2.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{ Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeContact, ItemType: details.ExchangeContact,
@ -133,18 +228,19 @@ var (
}, },
} }
ExchangeEventsRootPath = mustParsePath("tenant-id/exchange/user-id/events/holidays", false) ExchangeEventsRootPath = mustPathRep("tenant-id/exchange/user-id/events/holidays", false)
ExchangeEventsBasePath = mustAppendPath(ExchangeEventsRootPath, "holidays", false) ExchangeEventsBasePath = ExchangeEventsRootPath.mustAppend("holidays", false)
ExchangeEventsBasePath2 = mustAppendPath(ExchangeEventsRootPath, "moreholidays", false) ExchangeEventsBasePath2 = ExchangeEventsRootPath.mustAppend("moreholidays", false)
ExchangeEventsItemPath1 = mustAppendPath(ExchangeEventsBasePath, ItemName1, true) ExchangeEventsItemPath1 = ExchangeEventsBasePath.mustAppend(ItemName1, true)
ExchangeEventsItemPath2 = mustAppendPath(ExchangeEventsBasePath2, ItemName2, true) ExchangeEventsItemPath2 = ExchangeEventsBasePath2.mustAppend(ItemName2, true)
ExchangeEventsItems = []details.DetailsEntry{ ExchangeEventsItems = []details.DetailsEntry{
{ {
RepoRef: ExchangeEventsItemPath1.String(), RepoRef: ExchangeEventsItemPath1.RR.String(),
ShortRef: ExchangeEventsItemPath1.ShortRef(), ShortRef: ExchangeEventsItemPath1.RR.ShortRef(),
ParentRef: ExchangeEventsItemPath1.ToBuilder().Dir().ShortRef(), ParentRef: ExchangeEventsItemPath1.RR.ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath2.Item(), ItemRef: ExchangeEventsItemPath1.ItemLocation(),
LocationRef: ExchangeEventsItemPath1.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{ Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeEvent, ItemType: details.ExchangeEvent,
@ -156,10 +252,11 @@ var (
}, },
}, },
{ {
RepoRef: ExchangeEventsItemPath2.String(), RepoRef: ExchangeEventsItemPath2.RR.String(),
ShortRef: ExchangeEventsItemPath2.ShortRef(), ShortRef: ExchangeEventsItemPath2.RR.ShortRef(),
ParentRef: ExchangeEventsItemPath2.ToBuilder().Dir().ShortRef(), ParentRef: ExchangeEventsItemPath2.RR.ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath2.Item(), ItemRef: ExchangeEventsItemPath2.ItemLocation(),
LocationRef: ExchangeEventsItemPath2.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{ Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeEvent, ItemType: details.ExchangeEvent,
@ -172,30 +269,31 @@ var (
}, },
} }
OneDriveRootPath = mustParsePath("tenant-id/onedrive/user-id/files/drives/foo/root:", false) OneDriveRootPath = mustPathRep("tenant-id/onedrive/user-id/files/drives/foo/root:", false)
OneDriveFolderPath = mustAppendPath(OneDriveRootPath, "folder", false) OneDriveFolderPath = OneDriveRootPath.mustAppend("folder", false)
OneDriveBasePath1 = mustAppendPath(OneDriveFolderPath, "a", false) OneDriveBasePath1 = OneDriveFolderPath.mustAppend("a", false)
OneDriveBasePath2 = mustAppendPath(OneDriveFolderPath, "b", false) OneDriveBasePath2 = OneDriveFolderPath.mustAppend("b", false)
OneDriveItemPath1 = mustAppendPath(OneDriveFolderPath, ItemName1, true) OneDriveItemPath1 = OneDriveFolderPath.mustAppend(ItemName1, true)
OneDriveItemPath2 = mustAppendPath(OneDriveBasePath1, ItemName2, true) OneDriveItemPath2 = OneDriveBasePath1.mustAppend(ItemName2, true)
OneDriveItemPath3 = mustAppendPath(OneDriveBasePath2, ItemName3, true) OneDriveItemPath3 = OneDriveBasePath2.mustAppend(ItemName3, true)
OneDriveFolderFolder = stdpath.Join(OneDriveFolderPath.Folders()[3:]...) OneDriveFolderFolder = OneDriveFolderPath.loc.PopFront().String()
OneDriveParentFolder1 = stdpath.Join(OneDriveBasePath1.Folders()[3:]...) OneDriveParentFolder1 = OneDriveBasePath1.loc.PopFront().String()
OneDriveParentFolder2 = stdpath.Join(OneDriveBasePath2.Folders()[3:]...) OneDriveParentFolder2 = OneDriveBasePath2.loc.PopFront().String()
OneDriveItems = []details.DetailsEntry{ OneDriveItems = []details.DetailsEntry{
{ {
RepoRef: OneDriveItemPath1.String(), RepoRef: OneDriveItemPath1.RR.String(),
ShortRef: OneDriveItemPath1.ShortRef(), ShortRef: OneDriveItemPath1.RR.ShortRef(),
ParentRef: OneDriveItemPath1.ToBuilder().Dir().ShortRef(), ParentRef: OneDriveItemPath1.RR.ToBuilder().Dir().ShortRef(),
ItemRef: OneDriveItemPath1.Item(), ItemRef: OneDriveItemPath1.ItemLocation(),
LocationRef: OneDriveItemPath1.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{ OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem, ItemType: details.OneDriveItem,
ParentPath: OneDriveFolderFolder, ParentPath: OneDriveFolderFolder,
ItemName: OneDriveItemPath1.Item() + "name", ItemName: OneDriveItemPath1.ItemLocation() + "name",
Size: int64(23), Size: int64(23),
Owner: UserEmail1, Owner: UserEmail1,
Created: Time2, Created: Time2,
@ -204,15 +302,16 @@ var (
}, },
}, },
{ {
RepoRef: OneDriveItemPath2.String(), RepoRef: OneDriveItemPath2.RR.String(),
ShortRef: OneDriveItemPath2.ShortRef(), ShortRef: OneDriveItemPath2.RR.ShortRef(),
ParentRef: OneDriveItemPath2.ToBuilder().Dir().ShortRef(), ParentRef: OneDriveItemPath2.RR.ToBuilder().Dir().ShortRef(),
ItemRef: OneDriveItemPath2.Item(), ItemRef: OneDriveItemPath2.ItemLocation(),
LocationRef: OneDriveItemPath2.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{ OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem, ItemType: details.OneDriveItem,
ParentPath: OneDriveParentFolder1, ParentPath: OneDriveParentFolder1,
ItemName: OneDriveItemPath2.Item() + "name", ItemName: OneDriveItemPath2.ItemLocation() + "name",
Size: int64(42), Size: int64(42),
Owner: UserEmail1, Owner: UserEmail1,
Created: Time1, Created: Time1,
@ -221,15 +320,16 @@ var (
}, },
}, },
{ {
RepoRef: OneDriveItemPath3.String(), RepoRef: OneDriveItemPath3.RR.String(),
ShortRef: OneDriveItemPath3.ShortRef(), ShortRef: OneDriveItemPath3.RR.ShortRef(),
ParentRef: OneDriveItemPath3.ToBuilder().Dir().ShortRef(), ParentRef: OneDriveItemPath3.RR.ToBuilder().Dir().ShortRef(),
ItemRef: OneDriveItemPath3.Item(), ItemRef: OneDriveItemPath3.ItemLocation(),
LocationRef: OneDriveItemPath3.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{ OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem, ItemType: details.OneDriveItem,
ParentPath: OneDriveParentFolder2, ParentPath: OneDriveParentFolder2,
ItemName: OneDriveItemPath3.Item() + "name", ItemName: OneDriveItemPath3.ItemLocation() + "name",
Size: int64(19), Size: int64(19),
Owner: UserEmail2, Owner: UserEmail2,
Created: Time2, Created: Time2,
@ -239,30 +339,31 @@ var (
}, },
} }
SharePointRootPath = mustParsePath("tenant-id/sharepoint/site-id/libraries/drives/foo/root:", false) SharePointRootPath = mustPathRep("tenant-id/sharepoint/site-id/libraries/drives/foo/root:", false)
SharePointLibraryPath = mustAppendPath(SharePointRootPath, "library", false) SharePointLibraryPath = SharePointRootPath.mustAppend("library", false)
SharePointBasePath1 = mustAppendPath(SharePointLibraryPath, "a", false) SharePointBasePath1 = SharePointLibraryPath.mustAppend("a", false)
SharePointBasePath2 = mustAppendPath(SharePointLibraryPath, "b", false) SharePointBasePath2 = SharePointLibraryPath.mustAppend("b", false)
SharePointLibraryItemPath1 = mustAppendPath(SharePointLibraryPath, ItemName1, true) SharePointLibraryItemPath1 = SharePointLibraryPath.mustAppend(ItemName1, true)
SharePointLibraryItemPath2 = mustAppendPath(SharePointBasePath1, ItemName2, true) SharePointLibraryItemPath2 = SharePointBasePath1.mustAppend(ItemName2, true)
SharePointLibraryItemPath3 = mustAppendPath(SharePointBasePath2, ItemName3, true) SharePointLibraryItemPath3 = SharePointBasePath2.mustAppend(ItemName3, true)
SharePointLibraryFolder = stdpath.Join(SharePointLibraryPath.Folders()[3:]...) SharePointLibraryFolder = SharePointLibraryPath.loc.PopFront().String()
SharePointParentLibrary1 = stdpath.Join(SharePointBasePath1.Folders()[3:]...) SharePointParentLibrary1 = SharePointBasePath1.loc.PopFront().String()
SharePointParentLibrary2 = stdpath.Join(SharePointBasePath2.Folders()[3:]...) SharePointParentLibrary2 = SharePointBasePath2.loc.PopFront().String()
SharePointLibraryItems = []details.DetailsEntry{ SharePointLibraryItems = []details.DetailsEntry{
{ {
RepoRef: SharePointLibraryItemPath1.String(), RepoRef: SharePointLibraryItemPath1.RR.String(),
ShortRef: SharePointLibraryItemPath1.ShortRef(), ShortRef: SharePointLibraryItemPath1.RR.ShortRef(),
ParentRef: SharePointLibraryItemPath1.ToBuilder().Dir().ShortRef(), ParentRef: SharePointLibraryItemPath1.RR.ToBuilder().Dir().ShortRef(),
ItemRef: SharePointLibraryItemPath1.Item(), ItemRef: SharePointLibraryItemPath1.ItemLocation(),
LocationRef: SharePointLibraryItemPath1.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemType: details.SharePointLibrary, ItemType: details.SharePointLibrary,
ParentPath: SharePointLibraryFolder, ParentPath: SharePointLibraryFolder,
ItemName: SharePointLibraryItemPath1.Item() + "name", ItemName: SharePointLibraryItemPath1.ItemLocation() + "name",
Size: int64(23), Size: int64(23),
Owner: UserEmail1, Owner: UserEmail1,
Created: Time2, Created: Time2,
@ -271,15 +372,16 @@ var (
}, },
}, },
{ {
RepoRef: SharePointLibraryItemPath2.String(), RepoRef: SharePointLibraryItemPath2.RR.String(),
ShortRef: SharePointLibraryItemPath2.ShortRef(), ShortRef: SharePointLibraryItemPath2.RR.ShortRef(),
ParentRef: SharePointLibraryItemPath2.ToBuilder().Dir().ShortRef(), ParentRef: SharePointLibraryItemPath2.RR.ToBuilder().Dir().ShortRef(),
ItemRef: SharePointLibraryItemPath2.Item(), ItemRef: SharePointLibraryItemPath2.ItemLocation(),
LocationRef: SharePointLibraryItemPath2.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemType: details.SharePointLibrary, ItemType: details.SharePointLibrary,
ParentPath: SharePointParentLibrary1, ParentPath: SharePointParentLibrary1,
ItemName: SharePointLibraryItemPath2.Item() + "name", ItemName: SharePointLibraryItemPath2.ItemLocation() + "name",
Size: int64(42), Size: int64(42),
Owner: UserEmail1, Owner: UserEmail1,
Created: Time1, Created: Time1,
@ -288,15 +390,16 @@ var (
}, },
}, },
{ {
RepoRef: SharePointLibraryItemPath3.String(), RepoRef: SharePointLibraryItemPath3.RR.String(),
ShortRef: SharePointLibraryItemPath3.ShortRef(), ShortRef: SharePointLibraryItemPath3.RR.ShortRef(),
ParentRef: SharePointLibraryItemPath3.ToBuilder().Dir().ShortRef(), ParentRef: SharePointLibraryItemPath3.RR.ToBuilder().Dir().ShortRef(),
ItemRef: SharePointLibraryItemPath3.Item(), ItemRef: SharePointLibraryItemPath3.ItemLocation(),
LocationRef: SharePointLibraryItemPath3.loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemType: details.SharePointLibrary, ItemType: details.SharePointLibrary,
ParentPath: SharePointParentLibrary2, ParentPath: SharePointParentLibrary2,
ItemName: SharePointLibraryItemPath3.Item() + "name", ItemName: SharePointLibraryItemPath3.ItemLocation() + "name",
Size: int64(19), Size: int64(19),
Owner: UserEmail2, Owner: UserEmail2,
Created: Time2, Created: Time2,

View File

@ -123,9 +123,10 @@ var (
DetailsModel: details.DetailsModel{ DetailsModel: details.DetailsModel{
Entries: []details.DetailsEntry{ Entries: []details.DetailsEntry{
{ {
RepoRef: "tID/exchange/your-user-id/email/example/itemID", RepoRef: "tID/exchange/your-user-id/email/example/itemID",
ShortRef: "xyz", LocationRef: "example",
ItemRef: "123", ShortRef: "xyz",
ItemRef: "123",
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{ Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail, ItemType: details.ExchangeMail,

View File

@ -618,14 +618,10 @@ func (ec exchangeCategory) pathValues(
} }
result := map[categorizer][]string{ result := map[categorizer][]string{
folderCat: {repo.Folder(false)}, folderCat: {ent.LocationRef},
itemCat: {item, ent.ShortRef}, itemCat: {item, ent.ShortRef},
} }
if len(ent.LocationRef) > 0 {
result[folderCat] = append(result[folderCat], ent.LocationRef)
}
return result, nil return result, nil
} }

View File

@ -713,9 +713,9 @@ func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesInfo() {
func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesPath() { func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesPath() {
const ( const (
usr = "userID" usr = "userID"
fID1 = "mf_id_1" fID1 = "mf_id_1.d"
fld1 = "mailFolder" fld1 = "mailFolder"
fID2 = "mf_id_2" fID2 = "mf_id_2.d"
fld2 = "subFolder" fld2 = "subFolder"
mail = "mailID" mail = "mailID"
) )
@ -743,18 +743,18 @@ func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesPath() {
{"all folders", es.MailFolders(Any()), "", assert.True}, {"all folders", es.MailFolders(Any()), "", assert.True},
{"no folders", es.MailFolders(None()), "", assert.False}, {"no folders", es.MailFolders(None()), "", assert.False},
{"matching folder", es.MailFolders([]string{fld1}), "", assert.True}, {"matching folder", es.MailFolders([]string{fld1}), "", assert.True},
{"matching folder id", es.MailFolders([]string{fID1}), "", assert.True}, {"matching folder id", es.MailFolders([]string{fID1}), "", assert.False},
{"incomplete matching folder", es.MailFolders([]string{"mail"}), "", assert.False}, {"incomplete matching folder", es.MailFolders([]string{"mail"}), "", assert.False},
{"incomplete matching folder ID", es.MailFolders([]string{"mf_id"}), "", assert.False}, {"incomplete matching folder ID", es.MailFolders([]string{"mf_id"}), "", assert.False},
{"non-matching folder", es.MailFolders([]string{"smarf"}), "", assert.False}, {"non-matching folder", es.MailFolders([]string{"smarf"}), "", assert.False},
{"non-matching folder substring", es.MailFolders([]string{fld1 + "_suffix"}), "", assert.False}, {"non-matching folder substring", es.MailFolders([]string{fld1 + "_suffix"}), "", assert.False},
{"non-matching folder id substring", es.MailFolders([]string{fID1 + "_suffix"}), "", assert.False}, {"non-matching folder id substring", es.MailFolders([]string{fID1 + "_suffix"}), "", assert.False},
{"matching folder prefix", es.MailFolders([]string{fld1}, PrefixMatch()), "", assert.True}, {"matching folder prefix", es.MailFolders([]string{fld1}, PrefixMatch()), "", assert.True},
{"matching folder ID prefix", es.MailFolders([]string{fID1}, PrefixMatch()), "", assert.True}, {"matching folder ID prefix", es.MailFolders([]string{fID1}, PrefixMatch()), "", assert.False},
{"incomplete folder prefix", es.MailFolders([]string{"mail"}, PrefixMatch()), "", assert.False}, {"incomplete folder prefix", es.MailFolders([]string{"mail"}, PrefixMatch()), "", assert.False},
{"matching folder substring", es.MailFolders([]string{"Folder"}), "", assert.False}, {"matching folder substring", es.MailFolders([]string{"Folder"}), "", assert.False},
{"one of multiple folders", es.MailFolders([]string{"smarf", fld2}), "", assert.True}, {"one of multiple folders", es.MailFolders([]string{"smarf", fld2}), "", assert.True},
{"one of multiple folders by ID", es.MailFolders([]string{"smarf", fID2}), "", assert.True}, {"one of multiple folders by ID", es.MailFolders([]string{"smarf", fID2}), "", assert.False},
{"all mail", es.Mails(Any(), Any()), "", assert.True}, {"all mail", es.Mails(Any(), Any()), "", assert.True},
{"no mail", es.Mails(Any(), None()), "", assert.False}, {"no mail", es.Mails(Any(), None()), "", assert.False},
{"matching mail", es.Mails(Any(), []string{mail}), "", assert.True}, {"matching mail", es.Mails(Any(), []string{mail}), "", assert.True},
@ -777,10 +777,6 @@ func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesPath() {
aMatch = true aMatch = true
break break
} }
if matchesPathValues(scope, ExchangeMail, pvs) {
aMatch = true
break
}
} }
test.expect(t, aMatch) test.expect(t, aMatch)
}) })
@ -789,13 +785,41 @@ func (suite *ExchangeSelectorSuite) TestExchangeScope_MatchesPath() {
func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() { func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
var ( var (
contact = stubRepoRef(path.ExchangeService, path.ContactsCategory, "uid", "cfld", "cid") contact = stubPath(
event = stubRepoRef(path.ExchangeService, path.EventsCategory, "uid", "ecld", "eid") suite.T(),
mail = stubRepoRef(path.ExchangeService, path.EmailCategory, "uid", "mfld", "mid") "uid",
contactInSubFolder = stubRepoRef(path.ExchangeService, path.ContactsCategory, "uid", "cfld1/cfld2", "cid") []string{"cfld", "cid"},
path.ContactsCategory)
event = stubPath(
suite.T(),
"uid",
[]string{"efld", "eid"},
path.EventsCategory)
mail = stubPath(
suite.T(),
"uid",
[]string{"mfld", "mid"},
path.EmailCategory)
contactInSubFolder = stubPath(
suite.T(),
"uid",
[]string{"cfld1/cfld2", "cid"},
path.ContactsCategory)
) )
makeDeets := func(refs ...string) *details.Details { toRR := func(p path.Path) string {
newElems := []string{}
for _, e := range p.Folders() {
newElems = append(newElems, e+".d")
}
joinedFldrs := strings.Join(newElems, "/")
return stubRepoRef(p.Service(), p.Category(), p.ResourceOwner(), joinedFldrs, p.Item())
}
makeDeets := func(refs ...path.Path) *details.Details {
deets := &details.Details{ deets := &details.Details{
DetailsModel: details.DetailsModel{ DetailsModel: details.DetailsModel{
Entries: []details.DetailsEntry{}, Entries: []details.DetailsEntry{},
@ -815,7 +839,9 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
} }
deets.Entries = append(deets.Entries, details.DetailsEntry{ deets.Entries = append(deets.Entries, details.DetailsEntry{
RepoRef: r, RepoRef: toRR(r),
// Don't escape because we assume nice paths.
LocationRef: r.Folder(false),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{ Exchange: &details.ExchangeInfo{
ItemType: itype, ItemType: itype,
@ -851,7 +877,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Include(er.AllData()) er.Include(er.AllData())
return er return er
}, },
[]string{contact}, []string{toRR(contact)},
}, },
{ {
"event only", "event only",
@ -861,7 +887,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Include(er.AllData()) er.Include(er.AllData())
return er return er
}, },
[]string{event}, []string{toRR(event)},
}, },
{ {
"mail only", "mail only",
@ -871,7 +897,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Include(er.AllData()) er.Include(er.AllData())
return er return er
}, },
[]string{mail}, []string{toRR(mail)},
}, },
{ {
"all", "all",
@ -881,7 +907,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Include(er.AllData()) er.Include(er.AllData())
return er return er
}, },
[]string{contact, event, mail}, []string{toRR(contact), toRR(event), toRR(mail)},
}, },
{ {
"only match contact", "only match contact",
@ -891,7 +917,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Include(er.Contacts([]string{"cfld"}, []string{"cid"})) er.Include(er.Contacts([]string{"cfld"}, []string{"cid"}))
return er return er
}, },
[]string{contact}, []string{toRR(contact)},
}, },
{ {
"only match contactInSubFolder", "only match contactInSubFolder",
@ -901,7 +927,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Include(er.ContactFolders([]string{"cfld1/cfld2"})) er.Include(er.ContactFolders([]string{"cfld1/cfld2"}))
return er return er
}, },
[]string{contactInSubFolder}, []string{toRR(contactInSubFolder)},
}, },
{ {
"only match contactInSubFolder by prefix", "only match contactInSubFolder by prefix",
@ -911,7 +937,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Include(er.ContactFolders([]string{"cfld1/cfld2"}, PrefixMatch())) er.Include(er.ContactFolders([]string{"cfld1/cfld2"}, PrefixMatch()))
return er return er
}, },
[]string{contactInSubFolder}, []string{toRR(contactInSubFolder)},
}, },
{ {
"only match contactInSubFolder by leaf folder", "only match contactInSubFolder by leaf folder",
@ -921,17 +947,17 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Include(er.ContactFolders([]string{"cfld2"})) er.Include(er.ContactFolders([]string{"cfld2"}))
return er return er
}, },
[]string{contactInSubFolder}, []string{toRR(contactInSubFolder)},
}, },
{ {
"only match event", "only match event",
makeDeets(contact, event, mail), makeDeets(contact, event, mail),
func() *ExchangeRestore { func() *ExchangeRestore {
er := NewExchangeRestore([]string{"uid"}) er := NewExchangeRestore([]string{"uid"})
er.Include(er.Events([]string{"ecld"}, []string{"eid"})) er.Include(er.Events([]string{"efld"}, []string{"eid"}))
return er return er
}, },
[]string{event}, []string{toRR(event)},
}, },
{ {
"only match mail", "only match mail",
@ -941,7 +967,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Include(er.Mails([]string{"mfld"}, []string{"mid"})) er.Include(er.Mails([]string{"mfld"}, []string{"mid"}))
return er return er
}, },
[]string{mail}, []string{toRR(mail)},
}, },
{ {
"exclude contact", "exclude contact",
@ -952,7 +978,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Exclude(er.Contacts([]string{"cfld"}, []string{"cid"})) er.Exclude(er.Contacts([]string{"cfld"}, []string{"cid"}))
return er return er
}, },
[]string{event, mail}, []string{toRR(event), toRR(mail)},
}, },
{ {
"exclude event", "exclude event",
@ -960,10 +986,10 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
func() *ExchangeRestore { func() *ExchangeRestore {
er := NewExchangeRestore(Any()) er := NewExchangeRestore(Any())
er.Include(er.AllData()) er.Include(er.AllData())
er.Exclude(er.Events([]string{"ecld"}, []string{"eid"})) er.Exclude(er.Events([]string{"efld"}, []string{"eid"}))
return er return er
}, },
[]string{contact, mail}, []string{toRR(contact), toRR(mail)},
}, },
{ {
"exclude mail", "exclude mail",
@ -974,7 +1000,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Exclude(er.Mails([]string{"mfld"}, []string{"mid"})) er.Exclude(er.Mails([]string{"mfld"}, []string{"mid"}))
return er return er
}, },
[]string{contact, event}, []string{toRR(contact), toRR(event)},
}, },
{ {
"filter on mail subject", "filter on mail subject",
@ -991,7 +1017,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Filter(er.MailSubject("subj")) er.Filter(er.MailSubject("subj"))
return er return er
}, },
[]string{mail}, []string{toRR(mail)},
}, },
{ {
"filter on mail subject multiple input categories", "filter on mail subject multiple input categories",
@ -1012,7 +1038,7 @@ func (suite *ExchangeSelectorSuite) TestExchangeRestore_Reduce() {
er.Filter(er.MailSubject("subj")) er.Filter(er.MailSubject("subj"))
return er return er
}, },
[]string{mail}, []string{toRR(mail)},
}, },
} }
for _, test := range table { for _, test := range table {
@ -1466,38 +1492,43 @@ func (suite *ExchangeSelectorSuite) TestExchangeCategory_leafCat() {
func (suite *ExchangeSelectorSuite) TestExchangeCategory_PathValues() { func (suite *ExchangeSelectorSuite) TestExchangeCategory_PathValues() {
t := suite.T() t := suite.T()
contactPath := stubPath(t, "user", []string{"cfolder", "contactitem"}, path.ContactsCategory) contactPath := stubPath(t, "user", []string{"cfolder.d", "contactitem.d"}, path.ContactsCategory)
contactLoc := stubPath(t, "user", []string{"cfolder", "contactitem"}, path.ContactsCategory)
contactMap := map[categorizer][]string{ contactMap := map[categorizer][]string{
ExchangeContactFolder: {contactPath.Folder(false)}, ExchangeContactFolder: {contactLoc.Folder(false)},
ExchangeContact: {contactPath.Item(), "short"}, ExchangeContact: {contactPath.Item(), "short"},
} }
eventPath := stubPath(t, "user", []string{"ecalendar", "eventitem"}, path.EventsCategory) eventPath := stubPath(t, "user", []string{"ecalendar.d", "eventitem.d"}, path.EventsCategory)
eventLoc := stubPath(t, "user", []string{"ecalendar", "eventitem"}, path.EventsCategory)
eventMap := map[categorizer][]string{ eventMap := map[categorizer][]string{
ExchangeEventCalendar: {eventPath.Folder(false)}, ExchangeEventCalendar: {eventLoc.Folder(false)},
ExchangeEvent: {eventPath.Item(), "short"}, ExchangeEvent: {eventPath.Item(), "short"},
} }
mailPath := stubPath(t, "user", []string{"mfolder", "mailitem"}, path.EmailCategory) mailPath := stubPath(t, "user", []string{"mfolder.d", "mailitem.d"}, path.EmailCategory)
mailLoc := stubPath(t, "user", []string{"mfolder", "mailitem"}, path.EmailCategory)
mailMap := map[categorizer][]string{ mailMap := map[categorizer][]string{
ExchangeMailFolder: {mailPath.Folder(false)}, ExchangeMailFolder: {mailLoc.Folder(false)},
ExchangeMail: {mailPath.Item(), "short"}, ExchangeMail: {mailPath.Item(), "short"},
} }
table := []struct { table := []struct {
cat exchangeCategory cat exchangeCategory
path path.Path path path.Path
loc path.Path
expect map[categorizer][]string expect map[categorizer][]string
}{ }{
{ExchangeContact, contactPath, contactMap}, {ExchangeContact, contactPath, contactLoc, contactMap},
{ExchangeEvent, eventPath, eventMap}, {ExchangeEvent, eventPath, eventLoc, eventMap},
{ExchangeMail, mailPath, mailMap}, {ExchangeMail, mailPath, mailLoc, mailMap},
} }
for _, test := range table { for _, test := range table {
suite.Run(string(test.cat), func() { suite.Run(string(test.cat), func() {
t := suite.T() t := suite.T()
ent := details.DetailsEntry{ ent := details.DetailsEntry{
RepoRef: test.path.String(), RepoRef: test.path.String(),
ShortRef: "short", ShortRef: "short",
ItemRef: test.path.Item(), LocationRef: test.loc.Folder(true),
ItemRef: test.path.Item(),
} }
pvs, err := test.cat.pathValues(test.path, ent, Config{}) pvs, err := test.cat.pathValues(test.path, ent, Config{})

View File

@ -399,7 +399,7 @@ func (c oneDriveCategory) pathValues(
} }
// Ignore `drives/<driveID>/root:` for folder comparison // Ignore `drives/<driveID>/root:` for folder comparison
rFld := path.Builder{}.Append(repo.Folders()...).PopFront().PopFront().PopFront().String() rFld := ent.OneDrive.ParentPath
item := ent.ItemRef item := ent.ItemRef
if len(item) == 0 { if len(item) == 0 {

View File

@ -163,9 +163,27 @@ func (suite *OneDriveSelectorSuite) TestToOneDriveRestore() {
func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() { func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
var ( var (
file = stubRepoRef(path.OneDriveService, path.FilesCategory, "uid", "drive/driveID/root:/folderA/folderB", "file") file = stubRepoRef(
file2 = stubRepoRef(path.OneDriveService, path.FilesCategory, "uid", "drive/driveID/root:/folderA/folderC", "file2") path.OneDriveService,
file3 = stubRepoRef(path.OneDriveService, path.FilesCategory, "uid", "drive/driveID/root:/folderD/folderE", "file3") path.FilesCategory,
"uid",
"drive/driveID/root:/folderA.d/folderB.d",
"file")
fileParent = "folderA/folderB"
file2 = stubRepoRef(
path.OneDriveService,
path.FilesCategory,
"uid",
"drive/driveID/root:/folderA.d/folderC.d",
"file2")
fileParent2 = "folderA/folderC"
file3 = stubRepoRef(
path.OneDriveService,
path.FilesCategory,
"uid",
"drive/driveID/root:/folderD.d/folderE.d",
"file3")
fileParent3 = "folderD/folderE"
) )
deets := &details.Details{ deets := &details.Details{
@ -176,8 +194,9 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
ItemRef: "file", ItemRef: "file",
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{ OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem, ItemType: details.OneDriveItem,
ItemName: "fileName", ItemName: "fileName",
ParentPath: fileParent,
}, },
}, },
}, },
@ -186,8 +205,9 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
ItemRef: "file2", ItemRef: "file2",
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{ OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem, ItemType: details.OneDriveItem,
ItemName: "fileName2", ItemName: "fileName2",
ParentPath: fileParent2,
}, },
}, },
}, },
@ -196,8 +216,9 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
// item ref intentionally blank to assert fallback case // item ref intentionally blank to assert fallback case
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{ OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem, ItemType: details.OneDriveItem,
ItemName: "fileName3", ItemName: "fileName3",
ParentPath: fileParent3,
}, },
}, },
}, },
@ -211,14 +232,12 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
table := []struct { table := []struct {
name string name string
deets *details.Details
makeSelector func() *OneDriveRestore makeSelector func() *OneDriveRestore
expect []string expect []string
cfg Config cfg Config
}{ }{
{ {
name: "all", name: "all",
deets: deets,
makeSelector: func() *OneDriveRestore { makeSelector: func() *OneDriveRestore {
odr := NewOneDriveRestore(Any()) odr := NewOneDriveRestore(Any())
odr.Include(odr.AllData()) odr.Include(odr.AllData())
@ -227,8 +246,7 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
expect: arr(file, file2, file3), expect: arr(file, file2, file3),
}, },
{ {
name: "only match file", name: "only match file",
deets: deets,
makeSelector: func() *OneDriveRestore { makeSelector: func() *OneDriveRestore {
odr := NewOneDriveRestore(Any()) odr := NewOneDriveRestore(Any())
odr.Include(odr.Items(Any(), []string{"file2"})) odr.Include(odr.Items(Any(), []string{"file2"}))
@ -237,8 +255,7 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
expect: arr(file2), expect: arr(file2),
}, },
{ {
name: "id doesn't match name", name: "id doesn't match name",
deets: deets,
makeSelector: func() *OneDriveRestore { makeSelector: func() *OneDriveRestore {
odr := NewOneDriveRestore(Any()) odr := NewOneDriveRestore(Any())
odr.Include(odr.Items(Any(), []string{"file2"})) odr.Include(odr.Items(Any(), []string{"file2"}))
@ -248,8 +265,7 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
cfg: Config{OnlyMatchItemNames: true}, cfg: Config{OnlyMatchItemNames: true},
}, },
{ {
name: "only match file name", name: "only match file name",
deets: deets,
makeSelector: func() *OneDriveRestore { makeSelector: func() *OneDriveRestore {
odr := NewOneDriveRestore(Any()) odr := NewOneDriveRestore(Any())
odr.Include(odr.Items(Any(), []string{"fileName2"})) odr.Include(odr.Items(Any(), []string{"fileName2"}))
@ -259,8 +275,7 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
cfg: Config{OnlyMatchItemNames: true}, cfg: Config{OnlyMatchItemNames: true},
}, },
{ {
name: "name doesn't match id", name: "name doesn't match id",
deets: deets,
makeSelector: func() *OneDriveRestore { makeSelector: func() *OneDriveRestore {
odr := NewOneDriveRestore(Any()) odr := NewOneDriveRestore(Any())
odr.Include(odr.Items(Any(), []string{"fileName2"})) odr.Include(odr.Items(Any(), []string{"fileName2"}))
@ -269,8 +284,7 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
expect: []string{}, expect: []string{},
}, },
{ {
name: "only match folder", name: "only match folder",
deets: deets,
makeSelector: func() *OneDriveRestore { makeSelector: func() *OneDriveRestore {
odr := NewOneDriveRestore([]string{"uid"}) odr := NewOneDriveRestore([]string{"uid"})
odr.Include(odr.Folders([]string{"folderA/folderB", "folderA/folderC"})) odr.Include(odr.Folders([]string{"folderA/folderB", "folderA/folderC"}))
@ -288,7 +302,7 @@ func (suite *OneDriveSelectorSuite) TestOneDriveRestore_Reduce() {
sel := test.makeSelector() sel := test.makeSelector()
sel.Configure(test.cfg) sel.Configure(test.cfg)
results := sel.Reduce(ctx, test.deets, fault.New(true)) results := sel.Reduce(ctx, deets, fault.New(true))
paths := results.Paths() paths := results.Paths()
assert.Equal(t, test.expect, paths) assert.Equal(t, test.expect, paths)
}) })
@ -301,11 +315,13 @@ func (suite *OneDriveSelectorSuite) TestOneDriveCategory_PathValues() {
fileName := "file" fileName := "file"
fileID := fileName + "-id" fileID := fileName + "-id"
shortRef := "short" shortRef := "short"
elems := []string{"drive", "driveID", "root:", "dir1", "dir2", fileID} elems := []string{"drive", "driveID", "root:", "dir1.d", "dir2.d", fileID}
filePath, err := path.Build("tenant", "user", path.OneDriveService, path.FilesCategory, true, elems...) filePath, err := path.Build("tenant", "user", path.OneDriveService, path.FilesCategory, true, elems...)
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
fileLoc := path.Builder{}.Append("dir1", "dir2")
table := []struct { table := []struct {
name string name string
pathElems []string pathElems []string
@ -351,7 +367,8 @@ func (suite *OneDriveSelectorSuite) TestOneDriveCategory_PathValues() {
ItemRef: fileID, ItemRef: fileID,
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{ OneDrive: &details.OneDriveInfo{
ItemName: fileName, ItemName: fileName,
ParentPath: fileLoc.String(),
}, },
}, },
} }

View File

@ -48,7 +48,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
selFunc: func() selectors.Reducer { selFunc: func() selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.MailFolders( sel.Include(sel.MailFolders(
[]string{testdata.ExchangeEmailInboxPath.Folder(false)}, []string{testdata.ExchangeEmailInboxPath.FolderLocation()},
)) ))
return sel return sel
@ -72,7 +72,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
sel.Filter(sel.MailSender("a-person")) sel.Filter(sel.MailSender("a-person"))
sel.Exclude(sel.Mails( sel.Exclude(sel.Mails(
selectors.Any(), selectors.Any(),
[]string{testdata.ExchangeEmailItemPath2.ShortRef()}, []string{testdata.ExchangeEmailItemPath2.RR.ShortRef()},
)) ))
return sel return sel
@ -110,7 +110,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.Mails( sel.Include(sel.Mails(
selectors.Any(), selectors.Any(),
[]string{testdata.ExchangeEmailItemPath1.Item()}, []string{testdata.ExchangeEmailItemPath1.ItemLocation()},
)) ))
return sel return sel
@ -123,7 +123,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.Mails( sel.Include(sel.Mails(
selectors.Any(), selectors.Any(),
[]string{testdata.ExchangeEmailItemPath1.ShortRef()}, []string{testdata.ExchangeEmailItemPath1.RR.ShortRef()},
)) ))
return sel return sel
@ -177,7 +177,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
selFunc: func() selectors.Reducer { selFunc: func() selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.MailFolders( sel.Include(sel.MailFolders(
[]string{testdata.ExchangeEmailBasePath.Folder(false)}, []string{testdata.ExchangeEmailBasePath.FolderLocation()},
)) ))
return sel return sel
@ -192,7 +192,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
selFunc: func() selectors.Reducer { selFunc: func() selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.MailFolders( sel.Include(sel.MailFolders(
[]string{testdata.ExchangeEmailBasePath.Folder(false)}, []string{testdata.ExchangeEmailBasePath.FolderLocation()},
selectors.PrefixMatch(), // force prefix matching selectors.PrefixMatch(), // force prefix matching
)) ))
@ -205,7 +205,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
selFunc: func() selectors.Reducer { selFunc: func() selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.MailFolders( sel.Include(sel.MailFolders(
[]string{testdata.ExchangeEmailInboxPath.Folder(false)}, []string{testdata.ExchangeEmailInboxPath.FolderLocation()},
)) ))
return sel return sel
@ -217,7 +217,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
selFunc: func() selectors.Reducer { selFunc: func() selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.ContactFolders( sel.Include(sel.ContactFolders(
[]string{testdata.ExchangeContactsBasePath.Folder(false)}, []string{testdata.ExchangeContactsBasePath.FolderLocation()},
)) ))
return sel return sel
@ -229,7 +229,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
selFunc: func() selectors.Reducer { selFunc: func() selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.ContactFolders( sel.Include(sel.ContactFolders(
[]string{testdata.ExchangeContactsRootPath.Folder(false)}, []string{testdata.ExchangeContactsRootPath.FolderLocation()},
)) ))
return sel return sel
@ -242,7 +242,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
selFunc: func() selectors.Reducer { selFunc: func() selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.EventCalendars( sel.Include(sel.EventCalendars(
[]string{testdata.ExchangeEventsBasePath.Folder(false)}, []string{testdata.ExchangeEventsBasePath.FolderLocation()},
)) ))
return sel return sel
@ -254,7 +254,7 @@ func (suite *SelectorReduceSuite) TestReduce() {
selFunc: func() selectors.Reducer { selFunc: func() selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.EventCalendars( sel.Include(sel.EventCalendars(
[]string{testdata.ExchangeEventsRootPath.Folder(false)}, []string{testdata.ExchangeEventsRootPath.FolderLocation()},
)) ))
return sel return sel

View File

@ -520,9 +520,9 @@ func (c sharePointCategory) pathValues(
cfg Config, cfg Config,
) (map[categorizer][]string, error) { ) (map[categorizer][]string, error) {
var ( var (
folderCat, itemCat categorizer folderCat, itemCat categorizer
dropDriveFolderPrefix bool itemID string
itemID string rFld string
) )
switch c { switch c {
@ -531,25 +531,21 @@ func (c sharePointCategory) pathValues(
return nil, clues.New("no SharePoint ItemInfo in details") return nil, clues.New("no SharePoint ItemInfo in details")
} }
dropDriveFolderPrefix = true
folderCat, itemCat = SharePointLibraryFolder, SharePointLibraryItem folderCat, itemCat = SharePointLibraryFolder, SharePointLibraryItem
rFld = ent.SharePoint.ParentPath
case SharePointList, SharePointListItem: case SharePointList, SharePointListItem:
folderCat, itemCat = SharePointList, SharePointListItem folderCat, itemCat = SharePointList, SharePointListItem
rFld = ent.LocationRef
case SharePointPage, SharePointPageFolder: case SharePointPage, SharePointPageFolder:
folderCat, itemCat = SharePointPageFolder, SharePointPage folderCat, itemCat = SharePointPageFolder, SharePointPage
rFld = ent.LocationRef
default: default:
return nil, clues.New("unrecognized sharePointCategory").With("category", c) return nil, clues.New("unrecognized sharePointCategory").With("category", c)
} }
rFld := repo.Folder(false)
if dropDriveFolderPrefix {
// like onedrive, ignore `drives/<driveID>/root:` for library folder comparison
rFld = path.Builder{}.Append(repo.Folders()...).PopFront().PopFront().PopFront().String()
}
item := ent.ItemRef item := ent.ItemRef
if len(item) == 0 { if len(item) == 0 {
item = repo.Item() item = repo.Item()
@ -568,10 +564,6 @@ func (c sharePointCategory) pathValues(
result[itemCat] = append(result[itemCat], itemID) result[itemCat] = append(result[itemCat], itemID)
} }
if len(ent.LocationRef) > 0 {
result[folderCat] = append(result[folderCat], ent.LocationRef)
}
return result, nil return result, nil
} }

View File

@ -1,6 +1,7 @@
package selectors package selectors
import ( import (
"strings"
"testing" "testing"
"time" "time"
@ -8,6 +9,7 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"golang.org/x/exp/slices"
"github.com/alcionai/corso/src/internal/common" "github.com/alcionai/corso/src/internal/common"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
@ -204,67 +206,111 @@ func (suite *SharePointSelectorSuite) TestToSharePointRestore() {
} }
func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() { func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
toRR := func(cat path.CategoryType, siteID string, folders []string, item string) string {
folderElems := make([]string, 0, len(folders))
for _, f := range folders {
folderElems = append(folderElems, f+".d")
}
return stubRepoRef(
path.SharePointService,
cat,
siteID,
strings.Join(folderElems, "/"),
item)
}
var ( var (
drivePfx = "drive/drive!id/root:/" prefixElems = []string{
pairAC = "folderA/folderC" "drive",
pairGH = "folderG/folderH" "drive!id",
item = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", drivePfx+"folderA/folderB", "item") "root:",
item2 = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", drivePfx+pairAC, "item2") }
item3 = stubRepoRef(path.SharePointService, path.LibrariesCategory, "sid", drivePfx+"folderD/folderE", "item3") itemElems1 = []string{"folderA", "folderB"}
item4 = stubRepoRef(path.SharePointService, path.PagesCategory, "sid", pairGH, "item4") itemElems2 = []string{"folderA", "folderC"}
item5 = stubRepoRef(path.SharePointService, path.PagesCategory, "sid", pairGH, "item5") itemElems3 = []string{"folderD", "folderE"}
pairAC = "folderA/folderC"
pairGH = "folderG/folderH"
item = toRR(
path.LibrariesCategory,
"sid",
append(slices.Clone(prefixElems), itemElems1...),
"item")
item2 = toRR(
path.LibrariesCategory,
"sid",
append(slices.Clone(prefixElems), itemElems2...),
"item2")
item3 = toRR(
path.LibrariesCategory,
"sid",
append(slices.Clone(prefixElems), itemElems3...),
"item3")
item4 = stubRepoRef(path.SharePointService, path.PagesCategory, "sid", pairGH, "item4")
item5 = stubRepoRef(path.SharePointService, path.PagesCategory, "sid", pairGH, "item5")
) )
deets := &details.Details{ deets := &details.Details{
DetailsModel: details.DetailsModel{ DetailsModel: details.DetailsModel{
Entries: []details.DetailsEntry{ Entries: []details.DetailsEntry{
{ {
RepoRef: item, RepoRef: item,
ItemRef: "item", ItemRef: "item",
LocationRef: strings.Join(append([]string{"root:"}, itemElems1...), "/"),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemType: details.SharePointLibrary, ItemType: details.SharePointLibrary,
ItemName: "itemName", ItemName: "itemName",
ParentPath: strings.Join(itemElems1, "/"),
}, },
}, },
}, },
{ {
RepoRef: item2, RepoRef: item2,
LocationRef: strings.Join(append([]string{"root:"}, itemElems2...), "/"),
// ItemRef intentionally blank to test fallback case // ItemRef intentionally blank to test fallback case
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemType: details.SharePointLibrary, ItemType: details.SharePointLibrary,
ItemName: "itemName2", ItemName: "itemName2",
ParentPath: strings.Join(itemElems2, "/"),
}, },
}, },
}, },
{ {
RepoRef: item3, RepoRef: item3,
ItemRef: "item3", ItemRef: "item3",
LocationRef: strings.Join(append([]string{"root:"}, itemElems3...), "/"),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemType: details.SharePointLibrary, ItemType: details.SharePointLibrary,
ItemName: "itemName3", ItemName: "itemName3",
ParentPath: strings.Join(itemElems3, "/"),
}, },
}, },
}, },
{ {
RepoRef: item4, RepoRef: item4,
ItemRef: "item4", LocationRef: pairGH,
ItemRef: "item4",
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemType: details.SharePointPage, ItemType: details.SharePointPage,
ItemName: "itemName4", ItemName: "itemName4",
ParentPath: pairGH,
}, },
}, },
}, },
{ {
RepoRef: item5, RepoRef: item5,
LocationRef: pairGH,
// ItemRef intentionally blank to test fallback case // ItemRef intentionally blank to test fallback case
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemType: details.SharePointPage, ItemType: details.SharePointPage,
ItemName: "itemName5", ItemName: "itemName5",
ParentPath: pairGH,
}, },
}, },
}, },
@ -278,14 +324,12 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
table := []struct { table := []struct {
name string name string
deets *details.Details
makeSelector func() *SharePointRestore makeSelector func() *SharePointRestore
expect []string expect []string
cfg Config cfg Config
}{ }{
{ {
name: "all", name: "all",
deets: deets,
makeSelector: func() *SharePointRestore { makeSelector: func() *SharePointRestore {
odr := NewSharePointRestore(Any()) odr := NewSharePointRestore(Any())
odr.Include(odr.AllData()) odr.Include(odr.AllData())
@ -294,8 +338,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
expect: arr(item, item2, item3, item4, item5), expect: arr(item, item2, item3, item4, item5),
}, },
{ {
name: "only match item", name: "only match item",
deets: deets,
makeSelector: func() *SharePointRestore { makeSelector: func() *SharePointRestore {
odr := NewSharePointRestore(Any()) odr := NewSharePointRestore(Any())
odr.Include(odr.LibraryItems(Any(), []string{"item2"})) odr.Include(odr.LibraryItems(Any(), []string{"item2"}))
@ -304,8 +347,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
expect: arr(item2), expect: arr(item2),
}, },
{ {
name: "id doesn't match name", name: "id doesn't match name",
deets: deets,
makeSelector: func() *SharePointRestore { makeSelector: func() *SharePointRestore {
odr := NewSharePointRestore(Any()) odr := NewSharePointRestore(Any())
odr.Include(odr.LibraryItems(Any(), []string{"item2"})) odr.Include(odr.LibraryItems(Any(), []string{"item2"}))
@ -315,8 +357,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
cfg: Config{OnlyMatchItemNames: true}, cfg: Config{OnlyMatchItemNames: true},
}, },
{ {
name: "only match item name", name: "only match item name",
deets: deets,
makeSelector: func() *SharePointRestore { makeSelector: func() *SharePointRestore {
odr := NewSharePointRestore(Any()) odr := NewSharePointRestore(Any())
odr.Include(odr.LibraryItems(Any(), []string{"itemName2"})) odr.Include(odr.LibraryItems(Any(), []string{"itemName2"}))
@ -326,8 +367,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
cfg: Config{OnlyMatchItemNames: true}, cfg: Config{OnlyMatchItemNames: true},
}, },
{ {
name: "name doesn't match", name: "name doesn't match",
deets: deets,
makeSelector: func() *SharePointRestore { makeSelector: func() *SharePointRestore {
odr := NewSharePointRestore(Any()) odr := NewSharePointRestore(Any())
odr.Include(odr.LibraryItems(Any(), []string{"itemName2"})) odr.Include(odr.LibraryItems(Any(), []string{"itemName2"}))
@ -336,8 +376,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
expect: []string{}, expect: []string{},
}, },
{ {
name: "only match folder", name: "only match folder",
deets: deets,
makeSelector: func() *SharePointRestore { makeSelector: func() *SharePointRestore {
odr := NewSharePointRestore([]string{"sid"}) odr := NewSharePointRestore([]string{"sid"})
odr.Include(odr.LibraryFolders([]string{"folderA/folderB", pairAC})) odr.Include(odr.LibraryFolders([]string{"folderA/folderB", pairAC}))
@ -346,8 +385,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
expect: arr(item, item2), expect: arr(item, item2),
}, },
{ {
name: "pages match folder", name: "pages match folder",
deets: deets,
makeSelector: func() *SharePointRestore { makeSelector: func() *SharePointRestore {
odr := NewSharePointRestore([]string{"sid"}) odr := NewSharePointRestore([]string{"sid"})
odr.Include(odr.Pages([]string{pairGH, pairAC})) odr.Include(odr.Pages([]string{pairGH, pairAC}))
@ -365,7 +403,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
sel := test.makeSelector() sel := test.makeSelector()
sel.Configure(test.cfg) sel.Configure(test.cfg)
results := sel.Reduce(ctx, test.deets, fault.New(true)) results := sel.Reduce(ctx, deets, fault.New(true))
paths := results.Paths() paths := results.Paths()
assert.Equal(t, test.expect, paths) assert.Equal(t, test.expect, paths)
}) })
@ -377,21 +415,25 @@ func (suite *SharePointSelectorSuite) TestSharePointCategory_PathValues() {
itemName = "item" itemName = "item"
itemID = "item-id" itemID = "item-id"
shortRef = "short" shortRef = "short"
driveElems = []string{"drive", "drive!id", "root:", "dir1", "dir2", itemID} driveElems = []string{"drive", "drive!id", "root:.d", "dir1.d", "dir2.d", itemID}
elems = []string{"dir1", "dir2", itemID} elems = []string{"dir1", "dir2", itemID}
) )
table := []struct { table := []struct {
name string name string
sc sharePointCategory sc sharePointCategory
pathElems []string pathElems []string
expected map[categorizer][]string locRef string
cfg Config parentPath string
expected map[categorizer][]string
cfg Config
}{ }{
{ {
name: "SharePoint Libraries", name: "SharePoint Libraries",
sc: SharePointLibraryItem, sc: SharePointLibraryItem,
pathElems: driveElems, pathElems: driveElems,
locRef: "root:/dir1/dir2",
parentPath: "dir1/dir2",
expected: map[categorizer][]string{ expected: map[categorizer][]string{
SharePointLibraryFolder: {"dir1/dir2"}, SharePointLibraryFolder: {"dir1/dir2"},
SharePointLibraryItem: {itemID, shortRef}, SharePointLibraryItem: {itemID, shortRef},
@ -399,9 +441,11 @@ func (suite *SharePointSelectorSuite) TestSharePointCategory_PathValues() {
cfg: Config{}, cfg: Config{},
}, },
{ {
name: "SharePoint Libraries w/ name", name: "SharePoint Libraries w/ name",
sc: SharePointLibraryItem, sc: SharePointLibraryItem,
pathElems: driveElems, pathElems: driveElems,
locRef: "root:/dir1/dir2",
parentPath: "dir1/dir2",
expected: map[categorizer][]string{ expected: map[categorizer][]string{
SharePointLibraryFolder: {"dir1/dir2"}, SharePointLibraryFolder: {"dir1/dir2"},
SharePointLibraryItem: {itemName, shortRef}, SharePointLibraryItem: {itemName, shortRef},
@ -412,6 +456,7 @@ func (suite *SharePointSelectorSuite) TestSharePointCategory_PathValues() {
name: "SharePoint Lists", name: "SharePoint Lists",
sc: SharePointListItem, sc: SharePointListItem,
pathElems: elems, pathElems: elems,
locRef: "dir1/dir2",
expected: map[categorizer][]string{ expected: map[categorizer][]string{
SharePointList: {"dir1/dir2"}, SharePointList: {"dir1/dir2"},
SharePointListItem: {itemID, shortRef}, SharePointListItem: {itemID, shortRef},
@ -434,12 +479,14 @@ func (suite *SharePointSelectorSuite) TestSharePointCategory_PathValues() {
require.NoError(t, err, clues.ToCore(err)) require.NoError(t, err, clues.ToCore(err))
ent := details.DetailsEntry{ ent := details.DetailsEntry{
RepoRef: itemPath.String(), RepoRef: itemPath.String(),
ShortRef: shortRef, ShortRef: shortRef,
ItemRef: itemPath.Item(), ItemRef: itemPath.Item(),
LocationRef: test.locRef,
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{ SharePoint: &details.SharePointInfo{
ItemName: itemName, ItemName: itemName,
ParentPath: test.parentPath,
}, },
}, },
} }