Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements lists backup handler #4786

Merged
merged 8 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
}
3 changes: 3 additions & 0 deletions src/internal/m365/collection/site/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ type Collection struct {
ctrl control.Options
betaService *betaAPI.BetaService
statusUpdater support.StatusUpdater
getter getItemByIDer
}

// NewCollection helper function for creating a Collection
func NewCollection(
getter getItemByIDer,
folderPath path.Path,
ac api.Client,
scope selectors.SharePointScope,
Expand All @@ -70,6 +72,7 @@ func NewCollection(
c := &Collection{
fullPath: folderPath,
jobs: make([]string, 0),
getter: getter,
data: make(chan data.Item, collectionChannelBufferSize),
client: ac.Sites(),
statusUpdater: statusUpdater,
Expand Down
5 changes: 5 additions & 0 deletions src/internal/m365/collection/site/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/internal/data"
"github.com/alcionai/corso/src/internal/m365/collection/site/mock"
betaAPI "github.com/alcionai/corso/src/internal/m365/service/sharepoint/api"
spMock "github.com/alcionai/corso/src/internal/m365/service/sharepoint/mock"
"github.com/alcionai/corso/src/internal/tester"
Expand Down Expand Up @@ -77,13 +78,15 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() {
tables := []struct {
name, itemName string
scope selectors.SharePointScope
getter getItemByIDer
getDir func(t *testing.T) path.Path
getItem func(t *testing.T, itemName string) data.Item
}{
{
name: "List",
itemName: "MockListing",
scope: sel.Lists(selectors.Any())[0],
getter: mock.GetList{},
getDir: func(t *testing.T) path.Path {
dir, err := path.Build(
tenant,
Expand Down Expand Up @@ -120,6 +123,7 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() {
name: "Pages",
itemName: "MockPages",
scope: sel.Pages(selectors.Any())[0],
getter: nil,
getDir: func(t *testing.T) path.Path {
dir, err := path.Build(
tenant,
Expand Down Expand Up @@ -156,6 +160,7 @@ func (suite *SharePointCollectionSuite) TestCollection_Items() {
defer flush()

col := NewCollection(
test.getter,
test.getDir(t),
suite.ac,
test.scope,
Expand Down
15 changes: 15 additions & 0 deletions src/internal/m365/collection/site/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package site

import (
"context"

"github.com/microsoftgraph/msgraph-sdk-go/models"
)

type backupHandler interface {
getItemByIDer
}

type getItemByIDer interface {
GetItemByID(ctx context.Context, itemID string) (models.Listable, error)
}
27 changes: 27 additions & 0 deletions src/internal/m365/collection/site/lists_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package site

import (
"context"

"github.com/microsoftgraph/msgraph-sdk-go/models"

"github.com/alcionai/corso/src/pkg/services/m365/api"
)

var _ backupHandler = &listsBackupHandler{}

type listsBackupHandler struct {
ac api.Lists
protectedResource string
}

func NewListsBackupHandler(protectedResource string, ac api.Lists) listsBackupHandler {
return listsBackupHandler{
ac: ac,
protectedResource: protectedResource,
}
}

func (bh listsBackupHandler) GetItemByID(ctx context.Context, itemID string) (models.Listable, error) {
return bh.ac.GetListByID(ctx, bh.protectedResource, itemID)
}
20 changes: 20 additions & 0 deletions src/internal/m365/collection/site/mock/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package mock

import (
"context"

"github.com/microsoftgraph/msgraph-sdk-go/models"

"github.com/alcionai/corso/src/internal/common/ptr"
)

type GetList struct {
Err error
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: it's likely we'll later want to expand this to mock the whole backup handler. Might as well set it up now.

Suggested change
type GetList struct {
Err error
}
type ListHandler struct {
ListItem models.Listable
Err error
}


func (m GetList) GetItemByID(ctx context.Context, itemID string) (models.Listable, error) {
lst := models.NewList()
lst.SetId(ptr.To(itemID))

return lst, m.Err
}
3 changes: 3 additions & 0 deletions src/internal/m365/service/sharepoint/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ func ProduceBackupCollections(

switch scope.Category().PathType() {
case path.ListsCategory:
bh := site.NewListsBackupHandler(bpc.ProtectedResource.ID(), ac.Lists())

spcs, err = site.CollectLists(
ctx,
bh,
bpc,
ac,
creds.AzureTenantID,
Expand Down
Loading