Skip to content

Commit

Permalink
implements lists backup handler (#4786)
Browse files Browse the repository at this point in the history
<!-- PR description-->
introduces sharepoint backup handler
implements lists backup handler
instantiates and propagates the lists backup handler to downstream
add a test for CollectLists

#### Does this PR need a docs update or release note?
- [x] ⛔ No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [x] 🌻 Feature

#### Issue(s)
#4754 

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [x] ⚡ Unit test
- [x] 💚 E2E
  • Loading branch information
HiteshRepo committed Dec 21, 2023
1 parent b0f9e36 commit 010c46f
Show file tree
Hide file tree
Showing 9 changed files with 381 additions and 108 deletions.
16 changes: 10 additions & 6 deletions src/internal/m365/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/alcionai/corso/src/pkg/selectors"
selTD "github.com/alcionai/corso/src/pkg/selectors/testdata"
"github.com/alcionai/corso/src/pkg/services/m365/api"
"github.com/alcionai/corso/src/pkg/services/m365/api/graph"
)

// ---------------------------------------------------------------------------
Expand All @@ -53,6 +54,10 @@ func TestDataCollectionIntgSuite(t *testing.T) {
func (suite *DataCollectionIntgSuite) SetupSuite() {
t := suite.T()

ctx, flush := tester.NewContext(t)
defer flush()
graph.InitializeConcurrencyLimiter(ctx, false, 4)

suite.user = tconfig.M365UserID(t)
suite.site = tconfig.M365SiteID(t)

Expand Down Expand Up @@ -274,7 +279,6 @@ func (suite *DataCollectionIntgSuite) TestSharePointDataCollection() {
ctrl := newController(ctx, suite.T(), path.SharePointService)
tests := []struct {
name string
expected int
getSelector func() selectors.Selector
}{
{
Expand All @@ -286,8 +290,7 @@ func (suite *DataCollectionIntgSuite) TestSharePointDataCollection() {
},
},
{
name: "Lists",
expected: 0,
name: "Lists",
getSelector: func() selectors.Selector {
sel := selectors.NewSharePointBackup(selSites)
sel.Include(sel.Lists(selectors.Any()))
Expand Down Expand Up @@ -329,8 +332,8 @@ func (suite *DataCollectionIntgSuite) TestSharePointDataCollection() {
}

// we don't know an exact count of drives this will produce,
// but it should be more than one.
assert.Less(t, test.expected, len(collections))
// but it should be more than zero.
assert.NotEmpty(t, collections)

for _, coll := range collections {
for object := range coll.Items(ctx, fault.New(true)) {
Expand Down Expand Up @@ -465,7 +468,8 @@ func (suite *SPCollectionIntgSuite) TestCreateSharePointCollection_Lists() {
assert.True(t, excludes.Empty())

for _, collection := range cols {
t.Logf("Path: %s\n", collection.FullPath().String())
assert.Equal(t, path.SharePointService, collection.FullPath().Service())
assert.Equal(t, path.ListsCategory, collection.FullPath().Category())

for item := range collection.Items(ctx, fault.New(true)) {
t.Log("File: " + item.ID())
Expand Down
3 changes: 3 additions & 0 deletions src/internal/m365/collection/site/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func CollectPages(
}

collection := NewCollection(
nil,
dir,
ac,
scope,
Expand All @@ -139,6 +140,7 @@ func CollectPages(

func CollectLists(
ctx context.Context,
bh backupHandler,
bpc inject.BackupProducerConfig,
ac api.Client,
tenantID string,
Expand Down Expand Up @@ -175,6 +177,7 @@ func CollectLists(
}

collection := NewCollection(
bh,
dir,
ac,
scope,
Expand Down
54 changes: 49 additions & 5 deletions src/internal/m365/collection/site/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@ import (
"github.com/alcionai/corso/src/pkg/services/m365/api/graph"
)

type SharePointPagesSuite struct {
type SharePointSuite struct {
tester.Suite
}

func TestSharePointPagesSuite(t *testing.T) {
suite.Run(t, &SharePointPagesSuite{
func TestSharePointSuite(t *testing.T) {
suite.Run(t, &SharePointSuite{
Suite: tester.NewIntegrationSuite(
t,
[][]string{tconfig.M365AcctCredEnvs}),
})
}

func (suite *SharePointPagesSuite) SetupSuite() {
func (suite *SharePointSuite) SetupSuite() {
ctx, flush := tester.NewContext(suite.T())
defer flush()

graph.InitializeConcurrencyLimiter(ctx, false, 4)
}

func (suite *SharePointPagesSuite) TestCollectPages() {
func (suite *SharePointSuite) TestCollectPages() {
t := suite.T()

ctx, flush := tester.NewContext(t)
Expand Down Expand Up @@ -81,3 +81,47 @@ func (suite *SharePointPagesSuite) TestCollectPages() {
assert.NoError(t, err, clues.ToCore(err))
assert.NotEmpty(t, col)
}

func (suite *SharePointSuite) TestCollectLists() {
t := suite.T()

ctx, flush := tester.NewContext(t)
defer flush()

var (
siteID = tconfig.M365SiteID(t)
a = tconfig.NewM365Account(t)
counter = count.New()
)

creds, err := a.M365Config()
require.NoError(t, err, clues.ToCore(err))

ac, err := api.NewClient(
creds,
control.DefaultOptions(),
counter)
require.NoError(t, err, clues.ToCore(err))

bpc := inject.BackupProducerConfig{
LastBackupVersion: version.NoBackup,
Options: control.DefaultOptions(),
ProtectedResource: mock.NewProvider(siteID, siteID),
}

sel := selectors.NewSharePointBackup([]string{siteID})

bh := NewListsBackupHandler(bpc.ProtectedResource.ID(), ac.Lists())

col, err := CollectLists(
ctx,
bh,
bpc,
ac,
creds.AzureTenantID,
sel.Lists(selectors.Any())[0],
(&MockGraphService{}).UpdateStatus,
fault.New(true))
require.NoError(t, err, clues.ToCore(err))
assert.Less(t, 0, len(col))
}
Loading

0 comments on commit 010c46f

Please sign in to comment.