Add tests for older versions of backup details data (#3454)

Add tests for older backup details versions
including things like:
* SharePoint using OneDriveItem type
* not having LocationRef
* not having ItemRef
* folder names in RepoRef
* file names in RepoRef

Recommend viewing with ignore whitespace changes
---

#### 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)

* #3269

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [ ] 💚 E2E
This commit is contained in:
ashmrtn 2023-05-19 18:41:37 -07:00 committed by GitHub
parent a3f4d74944
commit f28c6e53d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1808 additions and 590 deletions

View File

@ -1,6 +1,7 @@
package backup package backup
import ( import (
"fmt"
"testing" "testing"
"github.com/alcionai/clues" "github.com/alcionai/clues"
@ -13,6 +14,8 @@ import (
"github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/cli/utils/testdata" "github.com/alcionai/corso/src/cli/utils/testdata"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/internal/version"
dtd "github.com/alcionai/corso/src/pkg/backup/details/testdata"
) )
type ExchangeUnitSuite struct { type ExchangeUnitSuite struct {
@ -275,18 +278,26 @@ func (suite *ExchangeUnitSuite) TestExchangeBackupDetailsSelectors() {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
for v := 0; v <= version.Backup; v++ {
suite.Run(fmt.Sprintf("version%d", v), func() {
for _, test := range testdata.ExchangeOptionDetailLookups { for _, test := range testdata.ExchangeOptionDetailLookups {
suite.Run(test.Name, func() { suite.Run(test.Name, func() {
t := suite.T() t := suite.T()
bg := testdata.VersionedBackupGetter{
Details: dtd.GetDetailsSetForVersion(t, v),
}
output, err := runDetailsExchangeCmd( output, err := runDetailsExchangeCmd(
ctx, ctx,
test.BackupGetter, bg,
"backup-ID", "backup-ID",
test.Opts, test.Opts(t, v),
false) false)
assert.NoError(t, err, clues.ToCore(err)) assert.NoError(t, err, clues.ToCore(err))
assert.ElementsMatch(t, test.Expected, output.Entries) assert.ElementsMatch(t, test.Expected(t, v), output.Entries)
})
}
}) })
} }
} }
@ -303,7 +314,7 @@ func (suite *ExchangeUnitSuite) TestExchangeBackupDetailsSelectorsBadFormats() {
ctx, ctx,
test.BackupGetter, test.BackupGetter,
"backup-ID", "backup-ID",
test.Opts, test.Opts(t, version.Backup),
false) false)
assert.Error(t, err, clues.ToCore(err)) assert.Error(t, err, clues.ToCore(err))
assert.Empty(t, output) assert.Empty(t, output)

View File

@ -1,6 +1,7 @@
package backup package backup
import ( import (
"fmt"
"testing" "testing"
"github.com/alcionai/clues" "github.com/alcionai/clues"
@ -13,6 +14,8 @@ import (
"github.com/alcionai/corso/src/cli/utils" "github.com/alcionai/corso/src/cli/utils"
"github.com/alcionai/corso/src/cli/utils/testdata" "github.com/alcionai/corso/src/cli/utils/testdata"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/internal/version"
dtd "github.com/alcionai/corso/src/pkg/backup/details/testdata"
) )
type OneDriveUnitSuite struct { type OneDriveUnitSuite struct {
@ -137,18 +140,26 @@ func (suite *OneDriveUnitSuite) TestOneDriveBackupDetailsSelectors() {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
for v := 0; v <= version.Backup; v++ {
suite.Run(fmt.Sprintf("version%d", v), func() {
for _, test := range testdata.OneDriveOptionDetailLookups { for _, test := range testdata.OneDriveOptionDetailLookups {
suite.Run(test.Name, func() { suite.Run(test.Name, func() {
t := suite.T() t := suite.T()
bg := testdata.VersionedBackupGetter{
Details: dtd.GetDetailsSetForVersion(t, v),
}
output, err := runDetailsOneDriveCmd( output, err := runDetailsOneDriveCmd(
ctx, ctx,
test.BackupGetter, bg,
"backup-ID", "backup-ID",
test.Opts, test.Opts(t, v),
false) false)
assert.NoError(t, err, clues.ToCore(err)) assert.NoError(t, err, clues.ToCore(err))
assert.ElementsMatch(t, test.Expected, output.Entries) assert.ElementsMatch(t, test.Expected(t, v), output.Entries)
})
}
}) })
} }
} }
@ -165,7 +176,7 @@ func (suite *OneDriveUnitSuite) TestOneDriveBackupDetailsSelectorsBadFormats() {
ctx, ctx,
test.BackupGetter, test.BackupGetter,
"backup-ID", "backup-ID",
test.Opts, test.Opts(t, version.Backup),
false) false)
assert.Error(t, err, clues.ToCore(err)) assert.Error(t, err, clues.ToCore(err))
assert.Empty(t, output) assert.Empty(t, output)

View File

@ -1,6 +1,7 @@
package backup package backup
import ( import (
"fmt"
"testing" "testing"
"github.com/alcionai/clues" "github.com/alcionai/clues"
@ -14,6 +15,8 @@ import (
"github.com/alcionai/corso/src/cli/utils/testdata" "github.com/alcionai/corso/src/cli/utils/testdata"
"github.com/alcionai/corso/src/internal/common/idname" "github.com/alcionai/corso/src/internal/common/idname"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/internal/version"
dtd "github.com/alcionai/corso/src/pkg/backup/details/testdata"
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
) )
@ -256,18 +259,26 @@ func (suite *SharePointUnitSuite) TestSharePointBackupDetailsSelectors() {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
for v := 0; v <= version.Backup; v++ {
suite.Run(fmt.Sprintf("version%d", v), func() {
for _, test := range testdata.SharePointOptionDetailLookups { for _, test := range testdata.SharePointOptionDetailLookups {
suite.Run(test.Name, func() { suite.Run(test.Name, func() {
t := suite.T() t := suite.T()
bg := testdata.VersionedBackupGetter{
Details: dtd.GetDetailsSetForVersion(t, v),
}
output, err := runDetailsSharePointCmd( output, err := runDetailsSharePointCmd(
ctx, ctx,
test.BackupGetter, bg,
"backup-ID", "backup-ID",
test.Opts, test.Opts(t, v),
false) false)
assert.NoError(t, err, clues.ToCore(err)) assert.NoError(t, err, clues.ToCore(err))
assert.ElementsMatch(t, test.Expected, output.Entries) assert.ElementsMatch(t, test.Expected(t, v), output.Entries)
})
}
}) })
} }
} }
@ -284,7 +295,7 @@ func (suite *SharePointUnitSuite) TestSharePointBackupDetailsSelectorsBadFormats
ctx, ctx,
test.BackupGetter, test.BackupGetter,
"backup-ID", "backup-ID",
test.Opts, test.Opts(t, version.Backup),
false) false)
assert.Error(t, err, clues.ToCore(err)) assert.Error(t, err, clues.ToCore(err))
assert.Empty(t, output) assert.Empty(t, output)

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,13 @@ package testdata
import ( import (
"strings" "strings"
"testing"
"time" "time"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
"github.com/alcionai/corso/src/internal/version"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/path" "github.com/alcionai/corso/src/pkg/path"
) )
@ -88,6 +93,28 @@ func (p repoRefAndLocRef) FolderLocation() string {
return p.Loc.Append(strings.TrimSuffix(lastElem, folderSuffix)).String() return p.Loc.Append(strings.TrimSuffix(lastElem, folderSuffix)).String()
} }
// locationAsRepoRef returns a path.Path where the LocationRef is used for the
// folder path instead of the id-based path elements. This is useful for
// generating paths for older versions of Corso.
func (p repoRefAndLocRef) locationAsRepoRef() path.Path {
tmp := p.Loc
if len(p.ItemLocation()) > 0 {
tmp = tmp.Append(p.ItemLocation())
}
res, err := tmp.ToDataLayerPath(
p.RR.Tenant(),
p.RR.ResourceOwner(),
p.RR.Service(),
p.RR.Category(),
len(p.ItemLocation()) > 0)
if err != nil {
panic(err)
}
return res
}
func mustPathRep(ref string, isItem bool) repoRefAndLocRef { func mustPathRep(ref string, isItem bool) repoRefAndLocRef {
res := repoRefAndLocRef{} res := repoRefAndLocRef{}
tmp := mustParsePath(ref, isItem) tmp := mustParsePath(ref, isItem)
@ -145,7 +172,10 @@ var (
ExchangeEmailItemPath2 = ExchangeEmailBasePath2.MustAppend(ItemName2, true) ExchangeEmailItemPath2 = ExchangeEmailBasePath2.MustAppend(ItemName2, true)
ExchangeEmailItemPath3 = ExchangeEmailBasePath3.MustAppend(ItemName3, true) ExchangeEmailItemPath3 = ExchangeEmailBasePath3.MustAppend(ItemName3, true)
ExchangeEmailItems = []details.Entry{ // These all represent the same set of items however, the different versions
// have varying amounts of information.
exchangeEmailItemsByVersion = map[int][]details.Entry{
version.All8MigrateUserPNToID: {
{ {
RepoRef: ExchangeEmailItemPath1.RR.String(), RepoRef: ExchangeEmailItemPath1.RR.String(),
ShortRef: ExchangeEmailItemPath1.RR.ShortRef(), ShortRef: ExchangeEmailItemPath1.RR.ShortRef(),
@ -191,6 +221,95 @@ var (
}, },
}, },
}, },
},
version.OneDrive7LocationRef: {
{
RepoRef: ExchangeEmailItemPath1.locationAsRepoRef().String(),
ShortRef: ExchangeEmailItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeEmailItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath1.ItemLocation(),
LocationRef: ExchangeEmailItemPath1.Loc.String(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Sender: "a-person",
Subject: "foo",
Received: Time1,
},
},
},
{
RepoRef: ExchangeEmailItemPath2.locationAsRepoRef().String(),
ShortRef: ExchangeEmailItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeEmailItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath2.ItemLocation(),
LocationRef: ExchangeEmailItemPath2.Loc.String(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Sender: "a-person",
Subject: "bar",
Received: Time2,
},
},
},
{
RepoRef: ExchangeEmailItemPath3.locationAsRepoRef().String(),
ShortRef: ExchangeEmailItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeEmailItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeEmailItemPath3.ItemLocation(),
LocationRef: ExchangeEmailItemPath3.Loc.String(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Sender: "another-person",
Subject: "baz",
Received: Time2,
},
},
},
},
0: {
{
RepoRef: ExchangeEmailItemPath1.locationAsRepoRef().String(),
ShortRef: ExchangeEmailItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeEmailItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Sender: "a-person",
Subject: "foo",
Received: Time1,
},
},
},
{
RepoRef: ExchangeEmailItemPath2.locationAsRepoRef().String(),
ShortRef: ExchangeEmailItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeEmailItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Sender: "a-person",
Subject: "bar",
Received: Time2,
},
},
},
{
RepoRef: ExchangeEmailItemPath3.locationAsRepoRef().String(),
ShortRef: ExchangeEmailItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeEmailItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeMail,
Sender: "another-person",
Subject: "baz",
Received: Time2,
},
},
},
},
} }
ExchangeContactsRootPath = mustPathRep("tenant-id/exchange/user-id/contacts/contacts", false) ExchangeContactsRootPath = mustPathRep("tenant-id/exchange/user-id/contacts/contacts", false)
@ -199,7 +318,8 @@ var (
ExchangeContactsItemPath1 = ExchangeContactsBasePath.MustAppend(ItemName1, true) ExchangeContactsItemPath1 = ExchangeContactsBasePath.MustAppend(ItemName1, true)
ExchangeContactsItemPath2 = ExchangeContactsBasePath2.MustAppend(ItemName2, true) ExchangeContactsItemPath2 = ExchangeContactsBasePath2.MustAppend(ItemName2, true)
ExchangeContactsItems = []details.Entry{ exchangeContactsItemsByVersion = map[int][]details.Entry{
version.All8MigrateUserPNToID: {
{ {
RepoRef: ExchangeContactsItemPath1.RR.String(), RepoRef: ExchangeContactsItemPath1.RR.String(),
ShortRef: ExchangeContactsItemPath1.RR.ShortRef(), ShortRef: ExchangeContactsItemPath1.RR.ShortRef(),
@ -226,6 +346,59 @@ var (
}, },
}, },
}, },
},
version.OneDrive7LocationRef: {
{
RepoRef: ExchangeContactsItemPath1.locationAsRepoRef().String(),
ShortRef: ExchangeContactsItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeContactsItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeContactsItemPath1.ItemLocation(),
LocationRef: ExchangeContactsItemPath1.Loc.String(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeContact,
ContactName: "a-person",
},
},
},
{
RepoRef: ExchangeContactsItemPath2.locationAsRepoRef().String(),
ShortRef: ExchangeContactsItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeContactsItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: ExchangeContactsItemPath2.ItemLocation(),
LocationRef: ExchangeContactsItemPath2.Loc.String(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeContact,
ContactName: "another-person",
},
},
},
},
0: {
{
RepoRef: ExchangeContactsItemPath1.locationAsRepoRef().String(),
ShortRef: ExchangeContactsItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeContactsItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeContact,
ContactName: "a-person",
},
},
},
{
RepoRef: ExchangeContactsItemPath2.locationAsRepoRef().String(),
ShortRef: ExchangeContactsItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeContactsItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeContact,
ContactName: "another-person",
},
},
},
},
} }
ExchangeEventsBasePath = mustPathRep("tenant-id/exchange/user-id/events/holidays", false) ExchangeEventsBasePath = mustPathRep("tenant-id/exchange/user-id/events/holidays", false)
@ -233,7 +406,8 @@ var (
ExchangeEventsItemPath1 = ExchangeEventsBasePath.MustAppend(ItemName1, true) ExchangeEventsItemPath1 = ExchangeEventsBasePath.MustAppend(ItemName1, true)
ExchangeEventsItemPath2 = ExchangeEventsBasePath2.MustAppend(ItemName2, true) ExchangeEventsItemPath2 = ExchangeEventsBasePath2.MustAppend(ItemName2, true)
ExchangeEventsItems = []details.Entry{ exchangeEventsItemsByVersion = map[int][]details.Entry{
version.All8MigrateUserPNToID: {
{ {
RepoRef: ExchangeEventsItemPath1.RR.String(), RepoRef: ExchangeEventsItemPath1.RR.String(),
ShortRef: ExchangeEventsItemPath1.RR.ShortRef(), ShortRef: ExchangeEventsItemPath1.RR.ShortRef(),
@ -266,6 +440,69 @@ var (
}, },
}, },
}, },
},
2: {
{
RepoRef: ExchangeEventsItemPath1.RR.String(),
ShortRef: ExchangeEventsItemPath1.RR.ShortRef(),
ParentRef: ExchangeEventsItemPath1.RR.ToBuilder().Dir().ShortRef(),
LocationRef: ExchangeEventsItemPath1.Loc.String(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeEvent,
Organizer: "a-person",
Subject: "foo",
EventStart: Time1,
EventRecurs: false,
},
},
},
{
RepoRef: ExchangeEventsItemPath2.RR.String(),
ShortRef: ExchangeEventsItemPath2.RR.ShortRef(),
ParentRef: ExchangeEventsItemPath2.RR.ToBuilder().Dir().ShortRef(),
LocationRef: ExchangeEventsItemPath2.Loc.String(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeEvent,
Organizer: "a-person",
Subject: "foo",
EventStart: Time2,
EventRecurs: true,
},
},
},
},
0: {
{
RepoRef: ExchangeEventsItemPath1.locationAsRepoRef().String(),
ShortRef: ExchangeEventsItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeEventsItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeEvent,
Organizer: "a-person",
Subject: "foo",
EventStart: Time1,
EventRecurs: false,
},
},
},
{
RepoRef: ExchangeEventsItemPath2.locationAsRepoRef().String(),
ShortRef: ExchangeEventsItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: ExchangeEventsItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
Exchange: &details.ExchangeInfo{
ItemType: details.ExchangeEvent,
Organizer: "a-person",
Subject: "foo",
EventStart: Time2,
EventRecurs: true,
},
},
},
},
} }
OneDriveRootPath = mustPathRep("tenant-id/onedrive/user-id/files/drives/foo/root:", false) OneDriveRootPath = mustPathRep("tenant-id/onedrive/user-id/files/drives/foo/root:", false)
@ -281,11 +518,12 @@ var (
OneDriveParentFolder1 = OneDriveBasePath1.Loc.PopFront().String() OneDriveParentFolder1 = OneDriveBasePath1.Loc.PopFront().String()
OneDriveParentFolder2 = OneDriveBasePath2.Loc.PopFront().String() OneDriveParentFolder2 = OneDriveBasePath2.Loc.PopFront().String()
OneDriveItems = []details.Entry{ oneDriveItemsByVersion = map[int][]details.Entry{
version.All8MigrateUserPNToID: {
{ {
RepoRef: OneDriveItemPath1.RR.String(), RepoRef: OneDriveItemPath1.locationAsRepoRef().String(),
ShortRef: OneDriveItemPath1.RR.ShortRef(), ShortRef: OneDriveItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath1.RR.ToBuilder().Dir().ShortRef(), ParentRef: OneDriveItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: OneDriveItemPath1.ItemLocation(), ItemRef: OneDriveItemPath1.ItemLocation(),
LocationRef: OneDriveItemPath1.Loc.String(), LocationRef: OneDriveItemPath1.Loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
@ -301,9 +539,9 @@ var (
}, },
}, },
{ {
RepoRef: OneDriveItemPath2.RR.String(), RepoRef: OneDriveItemPath2.locationAsRepoRef().String(),
ShortRef: OneDriveItemPath2.RR.ShortRef(), ShortRef: OneDriveItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath2.RR.ToBuilder().Dir().ShortRef(), ParentRef: OneDriveItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: OneDriveItemPath2.ItemLocation(), ItemRef: OneDriveItemPath2.ItemLocation(),
LocationRef: OneDriveItemPath2.Loc.String(), LocationRef: OneDriveItemPath2.Loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
@ -319,9 +557,9 @@ var (
}, },
}, },
{ {
RepoRef: OneDriveItemPath3.RR.String(), RepoRef: OneDriveItemPath3.locationAsRepoRef().String(),
ShortRef: OneDriveItemPath3.RR.ShortRef(), ShortRef: OneDriveItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath3.RR.ToBuilder().Dir().ShortRef(), ParentRef: OneDriveItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: OneDriveItemPath3.ItemLocation(), ItemRef: OneDriveItemPath3.ItemLocation(),
LocationRef: OneDriveItemPath3.Loc.String(), LocationRef: OneDriveItemPath3.Loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
@ -336,6 +574,160 @@ var (
}, },
}, },
}, },
},
version.OneDrive7LocationRef: {
{
RepoRef: OneDriveItemPath1.locationAsRepoRef().String(),
ShortRef: OneDriveItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
LocationRef: OneDriveItemPath1.Loc.String(),
ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ParentPath: OneDriveFolderFolder,
ItemName: OneDriveItemPath1.ItemLocation() + "name",
Size: int64(23),
Owner: UserEmail1,
Created: Time2,
Modified: Time4,
},
},
},
{
RepoRef: OneDriveItemPath2.locationAsRepoRef().String(),
ShortRef: OneDriveItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
LocationRef: OneDriveItemPath2.Loc.String(),
ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ParentPath: OneDriveParentFolder1,
ItemName: OneDriveItemPath2.ItemLocation() + "name",
Size: int64(42),
Owner: UserEmail1,
Created: Time1,
Modified: Time3,
},
},
},
{
RepoRef: OneDriveItemPath3.locationAsRepoRef().String(),
ShortRef: OneDriveItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
LocationRef: OneDriveItemPath3.Loc.String(),
ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ParentPath: OneDriveParentFolder2,
ItemName: OneDriveItemPath3.ItemLocation() + "name",
Size: int64(19),
Owner: UserEmail2,
Created: Time2,
Modified: Time4,
},
},
},
},
version.OneDrive6NameInMeta: {
{
RepoRef: OneDriveItemPath1.locationAsRepoRef().String(),
ShortRef: OneDriveItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ParentPath: OneDriveFolderFolder,
ItemName: OneDriveItemPath1.ItemLocation() + "name",
Size: int64(23),
Owner: UserEmail1,
Created: Time2,
Modified: Time4,
},
},
},
{
RepoRef: OneDriveItemPath2.locationAsRepoRef().String(),
ShortRef: OneDriveItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ParentPath: OneDriveParentFolder1,
ItemName: OneDriveItemPath2.ItemLocation() + "name",
Size: int64(42),
Owner: UserEmail1,
Created: Time1,
Modified: Time3,
},
},
},
{
RepoRef: OneDriveItemPath3.locationAsRepoRef().String(),
ShortRef: OneDriveItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ParentPath: OneDriveParentFolder2,
ItemName: OneDriveItemPath3.ItemLocation() + "name",
Size: int64(19),
Owner: UserEmail2,
Created: Time2,
Modified: Time4,
},
},
},
},
0: {
{
RepoRef: OneDriveItemPath1.locationAsRepoRef().String() + "name",
ShortRef: OneDriveItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ParentPath: OneDriveFolderFolder,
ItemName: OneDriveItemPath1.ItemLocation() + "name",
Size: int64(23),
Owner: UserEmail1,
Created: Time2,
Modified: Time4,
},
},
},
{
RepoRef: OneDriveItemPath2.locationAsRepoRef().String() + "name",
ShortRef: OneDriveItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ParentPath: OneDriveParentFolder1,
ItemName: OneDriveItemPath2.ItemLocation() + "name",
Size: int64(42),
Owner: UserEmail1,
Created: Time1,
Modified: Time3,
},
},
},
{
RepoRef: OneDriveItemPath3.locationAsRepoRef().String() + "name",
ShortRef: OneDriveItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: OneDriveItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
OneDrive: &details.OneDriveInfo{
ItemType: details.OneDriveItem,
ParentPath: OneDriveParentFolder2,
ItemName: OneDriveItemPath3.ItemLocation() + "name",
Size: int64(19),
Owner: UserEmail2,
Created: Time2,
Modified: Time4,
},
},
},
},
} }
SharePointRootPath = mustPathRep("tenant-id/sharepoint/site-id/libraries/drives/foo/root:", false) SharePointRootPath = mustPathRep("tenant-id/sharepoint/site-id/libraries/drives/foo/root:", false)
@ -351,11 +743,12 @@ var (
SharePointParentLibrary1 = SharePointBasePath1.Loc.PopFront().String() SharePointParentLibrary1 = SharePointBasePath1.Loc.PopFront().String()
SharePointParentLibrary2 = SharePointBasePath2.Loc.PopFront().String() SharePointParentLibrary2 = SharePointBasePath2.Loc.PopFront().String()
SharePointLibraryItems = []details.Entry{ sharePointLibraryItemsByVersion = map[int][]details.Entry{
version.All8MigrateUserPNToID: {
{ {
RepoRef: SharePointLibraryItemPath1.RR.String(), RepoRef: SharePointLibraryItemPath1.locationAsRepoRef().String(),
ShortRef: SharePointLibraryItemPath1.RR.ShortRef(), ShortRef: SharePointLibraryItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath1.RR.ToBuilder().Dir().ShortRef(), ParentRef: SharePointLibraryItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: SharePointLibraryItemPath1.ItemLocation(), ItemRef: SharePointLibraryItemPath1.ItemLocation(),
LocationRef: SharePointLibraryItemPath1.Loc.String(), LocationRef: SharePointLibraryItemPath1.Loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
@ -371,9 +764,9 @@ var (
}, },
}, },
{ {
RepoRef: SharePointLibraryItemPath2.RR.String(), RepoRef: SharePointLibraryItemPath2.locationAsRepoRef().String(),
ShortRef: SharePointLibraryItemPath2.RR.ShortRef(), ShortRef: SharePointLibraryItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath2.RR.ToBuilder().Dir().ShortRef(), ParentRef: SharePointLibraryItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: SharePointLibraryItemPath2.ItemLocation(), ItemRef: SharePointLibraryItemPath2.ItemLocation(),
LocationRef: SharePointLibraryItemPath2.Loc.String(), LocationRef: SharePointLibraryItemPath2.Loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
@ -389,9 +782,9 @@ var (
}, },
}, },
{ {
RepoRef: SharePointLibraryItemPath3.RR.String(), RepoRef: SharePointLibraryItemPath3.locationAsRepoRef().String(),
ShortRef: SharePointLibraryItemPath3.RR.ShortRef(), ShortRef: SharePointLibraryItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath3.RR.ToBuilder().Dir().ShortRef(), ParentRef: SharePointLibraryItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemRef: SharePointLibraryItemPath3.ItemLocation(), ItemRef: SharePointLibraryItemPath3.ItemLocation(),
LocationRef: SharePointLibraryItemPath3.Loc.String(), LocationRef: SharePointLibraryItemPath3.Loc.String(),
ItemInfo: details.ItemInfo{ ItemInfo: details.ItemInfo{
@ -406,30 +799,185 @@ var (
}, },
}, },
}, },
},
version.OneDrive7LocationRef: {
{
RepoRef: SharePointLibraryItemPath1.locationAsRepoRef().String(),
ShortRef: SharePointLibraryItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
LocationRef: SharePointLibraryItemPath1.Loc.String(),
ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{
ItemType: details.OneDriveItem,
ParentPath: SharePointLibraryFolder,
ItemName: SharePointLibraryItemPath1.ItemLocation() + "name",
Size: int64(23),
Owner: UserEmail1,
Created: Time2,
Modified: Time4,
},
},
},
{
RepoRef: SharePointLibraryItemPath2.locationAsRepoRef().String(),
ShortRef: SharePointLibraryItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
LocationRef: SharePointLibraryItemPath2.Loc.String(),
ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{
ItemType: details.OneDriveItem,
ParentPath: SharePointParentLibrary1,
ItemName: SharePointLibraryItemPath2.ItemLocation() + "name",
Size: int64(42),
Owner: UserEmail1,
Created: Time1,
Modified: Time3,
},
},
},
{
RepoRef: SharePointLibraryItemPath3.locationAsRepoRef().String(),
ShortRef: SharePointLibraryItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
LocationRef: SharePointLibraryItemPath3.Loc.String(),
ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{
ItemType: details.OneDriveItem,
ParentPath: SharePointParentLibrary2,
ItemName: SharePointLibraryItemPath3.ItemLocation() + "name",
Size: int64(19),
Owner: UserEmail2,
Created: Time2,
Modified: Time4,
},
},
},
},
version.OneDrive6NameInMeta: {
{
RepoRef: SharePointLibraryItemPath1.locationAsRepoRef().String(),
ShortRef: SharePointLibraryItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{
ItemType: details.OneDriveItem,
ParentPath: SharePointLibraryFolder,
ItemName: SharePointLibraryItemPath1.ItemLocation() + "name",
Size: int64(23),
Owner: UserEmail1,
Created: Time2,
Modified: Time4,
},
},
},
{
RepoRef: SharePointLibraryItemPath2.locationAsRepoRef().String(),
ShortRef: SharePointLibraryItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{
ItemType: details.OneDriveItem,
ParentPath: SharePointParentLibrary1,
ItemName: SharePointLibraryItemPath2.ItemLocation() + "name",
Size: int64(42),
Owner: UserEmail1,
Created: Time1,
Modified: Time3,
},
},
},
{
RepoRef: SharePointLibraryItemPath3.locationAsRepoRef().String(),
ShortRef: SharePointLibraryItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{
ItemType: details.OneDriveItem,
ParentPath: SharePointParentLibrary2,
ItemName: SharePointLibraryItemPath3.ItemLocation() + "name",
Size: int64(19),
Owner: UserEmail2,
Created: Time2,
Modified: Time4,
},
},
},
},
0: {
{
RepoRef: SharePointLibraryItemPath1.locationAsRepoRef().String() + "name",
ShortRef: SharePointLibraryItemPath1.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath1.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{
ItemType: details.OneDriveItem,
ParentPath: SharePointLibraryFolder,
ItemName: SharePointLibraryItemPath1.ItemLocation() + "name",
Size: int64(23),
Owner: UserEmail1,
Created: Time2,
Modified: Time4,
},
},
},
{
RepoRef: SharePointLibraryItemPath2.locationAsRepoRef().String() + "name",
ShortRef: SharePointLibraryItemPath2.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath2.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{
ItemType: details.OneDriveItem,
ParentPath: SharePointParentLibrary1,
ItemName: SharePointLibraryItemPath2.ItemLocation() + "name",
Size: int64(42),
Owner: UserEmail1,
Created: Time1,
Modified: Time3,
},
},
},
{
RepoRef: SharePointLibraryItemPath3.locationAsRepoRef().String() + "name",
ShortRef: SharePointLibraryItemPath3.locationAsRepoRef().ShortRef(),
ParentRef: SharePointLibraryItemPath3.locationAsRepoRef().ToBuilder().Dir().ShortRef(),
ItemInfo: details.ItemInfo{
SharePoint: &details.SharePointInfo{
ItemType: details.OneDriveItem,
ParentPath: SharePointParentLibrary2,
ItemName: SharePointLibraryItemPath3.ItemLocation() + "name",
Size: int64(19),
Owner: UserEmail2,
Created: Time2,
Modified: Time4,
},
},
},
},
} }
) )
func GetDetailsSet() *details.Details { func GetDetailsSetForVersion(t *testing.T, wantedVersion int) *details.Details {
entries := []details.Entry{} entries := []details.Entry{}
// TODO(ashmrtn): At some point make an exported variable somewhere that has
for _, e := range ExchangeEmailItems { // all the valid service/category pairs.
entries = append(entries, e) dataTypes := map[path.ServiceType][]path.CategoryType{
path.ExchangeService: {
path.EmailCategory,
path.EventsCategory,
path.ContactsCategory,
},
path.OneDriveService: {
path.FilesCategory,
},
path.SharePointService: {
path.LibrariesCategory,
},
} }
for _, e := range ExchangeContactsItems { for s, cats := range dataTypes {
entries = append(entries, e) for _, cat := range cats {
entries = append(entries, GetDeetsForVersion(t, s, cat, wantedVersion)...)
} }
for _, e := range ExchangeEventsItems {
entries = append(entries, e)
}
for _, e := range OneDriveItems {
entries = append(entries, e)
}
for _, e := range SharePointLibraryItems {
entries = append(entries, e)
} }
return &details.Details{ return &details.Details{
@ -438,3 +986,95 @@ func GetDetailsSet() *details.Details {
}, },
} }
} }
// GetItemsForVersion returns the set of items for the requested
// (service, category, version) tuple that reside at the indicated indices. If
// -1 is the only index provided then returns all items.
func GetItemsForVersion(
t *testing.T,
service path.ServiceType,
cat path.CategoryType,
wantVersion int,
indices ...int,
) []details.Entry {
deets := GetDeetsForVersion(t, service, cat, wantVersion)
if len(indices) == 1 && indices[0] == -1 {
return deets
}
var res []details.Entry
for _, i := range indices {
require.Less(t, i, len(deets), "requested index out of bounds", i, len(deets))
res = append(res, deets[i])
}
return res
}
// GetDeetsForVersion returns the set of details with the highest
// version <= the requested version.
func GetDeetsForVersion(
t *testing.T,
service path.ServiceType,
cat path.CategoryType,
wantVersion int,
) []details.Entry {
var input map[int][]details.Entry
switch service {
case path.ExchangeService:
switch cat {
case path.EmailCategory:
input = exchangeEmailItemsByVersion
case path.EventsCategory:
input = exchangeEventsItemsByVersion
case path.ContactsCategory:
input = exchangeContactsItemsByVersion
}
case path.OneDriveService:
if cat == path.FilesCategory {
input = oneDriveItemsByVersion
}
case path.SharePointService:
if cat == path.LibrariesCategory {
input = sharePointLibraryItemsByVersion
}
}
require.NotNil(
t,
input,
"unsupported (service, category)",
service.String(),
cat.String())
return getDeetsForVersion(t, wantVersion, input)
}
func getDeetsForVersion(
t *testing.T,
wantVersion int,
deetsSet map[int][]details.Entry,
) []details.Entry {
var (
res []details.Entry
resVersion = version.NoBackup
)
for v, deets := range deetsSet {
if v <= wantVersion && v > resVersion {
resVersion = v
res = deets
}
}
require.NotEmpty(t, res, "unable to find details for version", wantVersion)
return slices.Clone(res)
}

View File

@ -1,6 +1,7 @@
package selectors_test package selectors_test
import ( import (
"fmt"
"testing" "testing"
"time" "time"
@ -9,9 +10,11 @@ import (
"github.com/alcionai/corso/src/internal/common/dttm" "github.com/alcionai/corso/src/internal/common/dttm"
"github.com/alcionai/corso/src/internal/tester" "github.com/alcionai/corso/src/internal/tester"
"github.com/alcionai/corso/src/internal/version"
"github.com/alcionai/corso/src/pkg/backup/details" "github.com/alcionai/corso/src/pkg/backup/details"
"github.com/alcionai/corso/src/pkg/backup/details/testdata" "github.com/alcionai/corso/src/pkg/backup/details/testdata"
"github.com/alcionai/corso/src/pkg/fault" "github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/selectors" "github.com/alcionai/corso/src/pkg/selectors"
) )
@ -27,25 +30,31 @@ func (suite *SelectorReduceSuite) TestReduce() {
ctx, flush := tester.NewContext() ctx, flush := tester.NewContext()
defer flush() defer flush()
allDetails := testdata.GetDetailsSet()
table := []struct { table := []struct {
name string name string
selFunc func() selectors.Reducer selFunc func(t *testing.T, wantVersion int) selectors.Reducer
expected []details.Entry expected func(t *testing.T, wantVersion int) []details.Entry
}{ }{
{ {
name: "ExchangeAllMail", name: "ExchangeAllMail",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.Mails(selectors.Any(), selectors.Any())) sel.Include(sel.Mails(selectors.Any(), selectors.Any()))
return sel return sel
}, },
expected: testdata.ExchangeEmailItems, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
-1)
},
}, },
{ {
name: "ExchangeMailFolderPrefixMatch", name: "ExchangeMailFolderPrefixMatch",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.MailFolders( sel.Include(sel.MailFolders(
[]string{testdata.ExchangeEmailInboxPath.FolderLocation()}, []string{testdata.ExchangeEmailInboxPath.FolderLocation()},
@ -53,48 +62,79 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: testdata.ExchangeEmailItems, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
-1)
},
}, },
{ {
name: "ExchangeMailSubject", name: "ExchangeMailSubject",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Filter(sel.MailSubject("foo")) sel.Filter(sel.MailSubject("foo"))
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeEmailItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
0)
},
}, },
{ {
name: "ExchangeMailSubjectExcludeItem", name: "ExchangeMailSubjectExcludeItem",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
deets := testdata.GetDeetsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion)
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
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.RR.ShortRef()}, []string{deets[1].ShortRef},
)) ))
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeEmailItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
0)
},
}, },
{ {
name: "ExchangeMailSender", name: "ExchangeMailSender",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Filter(sel.MailSender("a-person")) sel.Filter(sel.MailSender("a-person"))
return sel return sel
}, },
expected: []details.Entry{ expected: func(t *testing.T, wantVersion int) []details.Entry {
testdata.ExchangeEmailItems[0], return testdata.GetItemsForVersion(
testdata.ExchangeEmailItems[1], t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
0, 1)
}, },
}, },
{ {
name: "ExchangeMailReceivedTime", name: "ExchangeMailReceivedTime",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Filter(sel.MailReceivedBefore( sel.Filter(sel.MailReceivedBefore(
dttm.Format(testdata.Time1.Add(time.Second)), dttm.Format(testdata.Time1.Add(time.Second)),
@ -102,11 +142,18 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeEmailItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
0)
},
}, },
{ {
name: "ExchangeMailID", name: "ExchangeMailID",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.Mails( sel.Include(sel.Mails(
selectors.Any(), selectors.Any(),
@ -115,24 +162,44 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeEmailItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
0)
},
}, },
{ {
name: "ExchangeMailShortRef", name: "ExchangeMailShortRef",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
deets := testdata.GetDeetsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion)
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.RR.ShortRef()}, []string{deets[0].ShortRef},
)) ))
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeEmailItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
0)
},
}, },
{ {
name: "ExchangeAllEventsAndMailWithSubject", name: "ExchangeAllEventsAndMailWithSubject",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.Events( sel.Include(sel.Events(
selectors.Any(), selectors.Any(),
@ -142,39 +209,62 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeEmailItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
0)
},
}, },
{ {
name: "ExchangeEventsAndMailWithSubject", name: "ExchangeEventsAndMailWithSubject",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Filter(sel.EventSubject("foo")) sel.Filter(sel.EventSubject("foo"))
sel.Filter(sel.MailSubject("foo")) sel.Filter(sel.MailSubject("foo"))
return sel return sel
}, },
expected: []details.Entry{}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return []details.Entry{}
},
}, },
{ {
name: "ExchangeAll", name: "ExchangeAll",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.AllData()) sel.Include(sel.AllData())
return sel return sel
}, },
expected: append( expected: func(t *testing.T, wantVersion int) []details.Entry {
return append(
append( append(
append( testdata.GetItemsForVersion(
[]details.Entry{}, t,
testdata.ExchangeEmailItems...), path.ExchangeService,
testdata.ExchangeContactsItems...), path.EmailCategory,
testdata.ExchangeEventsItems..., wantVersion,
), -1),
testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EventsCategory,
wantVersion,
-1)...),
testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.ContactsCategory,
wantVersion,
-1)...)
},
}, },
{ {
name: "ExchangeMailByFolder", name: "ExchangeMailByFolder",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.MailFolders( sel.Include(sel.MailFolders(
[]string{testdata.ExchangeEmailBasePath.FolderLocation()}, []string{testdata.ExchangeEmailBasePath.FolderLocation()},
@ -182,14 +272,21 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeEmailItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
0)
},
}, },
// TODO (keepers): all folders are treated as prefix-matches at this time. // TODO (keepers): all folders are treated as prefix-matches at this time.
// so this test actually does nothing different. In the future, we'll // so this test actually does nothing different. In the future, we'll
// need to amend the non-prefix folder tests to expect non-prefix matches. // need to amend the non-prefix folder tests to expect non-prefix matches.
{ {
name: "ExchangeMailByFolderPrefix", name: "ExchangeMailByFolderPrefix",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.MailFolders( sel.Include(sel.MailFolders(
[]string{testdata.ExchangeEmailBasePath.FolderLocation()}, []string{testdata.ExchangeEmailBasePath.FolderLocation()},
@ -198,11 +295,18 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeEmailItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
0)
},
}, },
{ {
name: "ExchangeMailByFolderRoot", name: "ExchangeMailByFolderRoot",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.MailFolders( sel.Include(sel.MailFolders(
[]string{testdata.ExchangeEmailInboxPath.FolderLocation()}, []string{testdata.ExchangeEmailInboxPath.FolderLocation()},
@ -210,11 +314,18 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: testdata.ExchangeEmailItems, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EmailCategory,
wantVersion,
-1)
},
}, },
{ {
name: "ExchangeContactByFolder", name: "ExchangeContactByFolder",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.ContactFolders( sel.Include(sel.ContactFolders(
[]string{testdata.ExchangeContactsBasePath.FolderLocation()}, []string{testdata.ExchangeContactsBasePath.FolderLocation()},
@ -222,11 +333,18 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeContactsItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.ContactsCategory,
wantVersion,
0)
},
}, },
{ {
name: "ExchangeContactByFolderRoot", name: "ExchangeContactByFolderRoot",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.ContactFolders( sel.Include(sel.ContactFolders(
[]string{testdata.ExchangeContactsRootPath.FolderLocation()}, []string{testdata.ExchangeContactsRootPath.FolderLocation()},
@ -234,12 +352,19 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: testdata.ExchangeContactsItems, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.ContactsCategory,
wantVersion,
-1)
},
}, },
{ {
name: "ExchangeEventsByFolder", name: "ExchangeEventsByFolder",
selFunc: func() selectors.Reducer { selFunc: func(t *testing.T, wantVersion int) selectors.Reducer {
sel := selectors.NewExchangeRestore(selectors.Any()) sel := selectors.NewExchangeRestore(selectors.Any())
sel.Include(sel.EventCalendars( sel.Include(sel.EventCalendars(
[]string{testdata.ExchangeEventsBasePath.FolderLocation()}, []string{testdata.ExchangeEventsBasePath.FolderLocation()},
@ -247,16 +372,28 @@ func (suite *SelectorReduceSuite) TestReduce() {
return sel return sel
}, },
expected: []details.Entry{testdata.ExchangeEventsItems[0]}, expected: func(t *testing.T, wantVersion int) []details.Entry {
return testdata.GetItemsForVersion(
t,
path.ExchangeService,
path.EventsCategory,
wantVersion,
0)
},
}, },
} }
for v := 0; v <= version.Backup; v++ {
suite.Run(fmt.Sprintf("version%d", v), func() {
for _, test := range table { for _, test := range table {
suite.Run(test.name, func() { suite.Run(test.name, func() {
t := suite.T() t := suite.T()
output := test.selFunc().Reduce(ctx, allDetails, fault.New(true)) allDetails := testdata.GetDetailsSetForVersion(t, v)
assert.ElementsMatch(t, test.expected, output.Entries) output := test.selFunc(t, v).Reduce(ctx, allDetails, fault.New(true))
assert.ElementsMatch(t, test.expected(t, v), output.Entries)
})
}
}) })
} }
} }