migrate sharepoint cat from file to library (#1555)
## Description Adds a LibraryCategory in paths, and changes the current sharepoint code to use that cat instead of the onedrive files cat. This is mostly to keep sharepoint library drives separate from onedrive and sharepoint site list items. ## Type of change - [x] 🌻 Feature ## Issue(s) * #1506 ## Test Plan - [x] ⚡ Unit test
This commit is contained in:
parent
10acf0ccf6
commit
5b0549fb32
@ -172,7 +172,7 @@ func (suite *ConnectorDataCollectionIntegrationSuite) TestSharePointDataCollecti
|
|||||||
name: "Items - TODO: actual sharepoint categories",
|
name: "Items - TODO: actual sharepoint categories",
|
||||||
getSelector: func(t *testing.T) selectors.Selector {
|
getSelector: func(t *testing.T) selectors.Selector {
|
||||||
sel := selectors.NewSharePointBackup()
|
sel := selectors.NewSharePointBackup()
|
||||||
sel.Include(sel.Folders([]string{suite.site}, selectors.Any()))
|
sel.Include(sel.Libraries([]string{suite.site}, selectors.Any()))
|
||||||
|
|
||||||
return sel.Selector
|
return sel.Selector
|
||||||
},
|
},
|
||||||
@ -509,7 +509,7 @@ func (suite *ConnectorCreateSharePointCollectionIntegrationSuite) TestCreateShar
|
|||||||
sel = selectors.NewSharePointBackup()
|
sel = selectors.NewSharePointBackup()
|
||||||
)
|
)
|
||||||
|
|
||||||
sel.Include(sel.Folders(
|
sel.Include(sel.Libraries(
|
||||||
[]string{siteID},
|
[]string{siteID},
|
||||||
[]string{"foo"},
|
[]string{"foo"},
|
||||||
selectors.PrefixMatch(),
|
selectors.PrefixMatch(),
|
||||||
|
|||||||
@ -81,6 +81,8 @@ func StringToPathCategory(input string) path.CategoryType {
|
|||||||
return path.EventsCategory
|
return path.EventsCategory
|
||||||
case "files":
|
case "files":
|
||||||
return path.FilesCategory
|
return path.FilesCategory
|
||||||
|
case "libraries":
|
||||||
|
return path.LibrariesCategory
|
||||||
default:
|
default:
|
||||||
return path.UnknownCategory
|
return path.UnknownCategory
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import (
|
|||||||
func mustToDataLayerPath(
|
func mustToDataLayerPath(
|
||||||
t *testing.T,
|
t *testing.T,
|
||||||
service path.ServiceType,
|
service path.ServiceType,
|
||||||
tenant, user string,
|
tenant, resourceOwner string,
|
||||||
category path.CategoryType,
|
category path.CategoryType,
|
||||||
elements []string,
|
elements []string,
|
||||||
isItem bool,
|
isItem bool,
|
||||||
@ -37,11 +37,13 @@ func mustToDataLayerPath(
|
|||||||
|
|
||||||
switch service {
|
switch service {
|
||||||
case path.ExchangeService:
|
case path.ExchangeService:
|
||||||
res, err = pb.ToDataLayerExchangePathForCategory(tenant, user, category, isItem)
|
res, err = pb.ToDataLayerExchangePathForCategory(tenant, resourceOwner, category, isItem)
|
||||||
case path.OneDriveService:
|
case path.OneDriveService:
|
||||||
require.Equal(t, path.FilesCategory, category)
|
require.Equal(t, path.FilesCategory, category)
|
||||||
|
|
||||||
res, err = pb.ToDataLayerOneDrivePath(tenant, user, isItem)
|
res, err = pb.ToDataLayerOneDrivePath(tenant, resourceOwner, isItem)
|
||||||
|
case path.SharePointService:
|
||||||
|
res, err = pb.ToDataLayerSharePointPath(tenant, resourceOwner, category, isItem)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
err = errors.Errorf("bad service type %s", service.String())
|
err = errors.Errorf("bad service type %s", service.String())
|
||||||
|
|||||||
@ -170,7 +170,7 @@ func GetCanonicalPath(p, tenant, resourceOwner string, source driveSource) (path
|
|||||||
case OneDriveSource:
|
case OneDriveSource:
|
||||||
result, err = pathBuilder.ToDataLayerOneDrivePath(tenant, resourceOwner, false)
|
result, err = pathBuilder.ToDataLayerOneDrivePath(tenant, resourceOwner, false)
|
||||||
case SharePointSource:
|
case SharePointSource:
|
||||||
result, err = pathBuilder.ToDataLayerSharePointPath(tenant, resourceOwner, false)
|
result, err = pathBuilder.ToDataLayerSharePointPath(tenant, resourceOwner, path.LibrariesCategory, false)
|
||||||
default:
|
default:
|
||||||
return nil, errors.Errorf("unrecognized drive data source")
|
return nil, errors.Errorf("unrecognized drive data source")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,7 +59,7 @@ func (suite *OneDriveCollectionsSuite) TestGetCanonicalPath() {
|
|||||||
name: "sharepoint",
|
name: "sharepoint",
|
||||||
source: SharePointSource,
|
source: SharePointSource,
|
||||||
dir: []string{"sharepoint"},
|
dir: []string{"sharepoint"},
|
||||||
expect: "tenant/sharepoint/resourceOwner/files/sharepoint",
|
expect: "tenant/sharepoint/resourceOwner/libraries/sharepoint",
|
||||||
expectErr: assert.NoError,
|
expectErr: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -256,6 +256,7 @@ func (suite *OneDriveCollectionsSuite) TestUpdateCollections() {
|
|||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
c := NewCollections(tenant, user, OneDriveSource, testFolderMatcher{tt.scope}, &MockGraphService{}, nil)
|
c := NewCollections(tenant, user, OneDriveSource, testFolderMatcher{tt.scope}, &MockGraphService{}, nil)
|
||||||
|
|
||||||
err := c.UpdateCollections(ctx, "driveID", tt.items)
|
err := c.UpdateCollections(ctx, "driveID", tt.items)
|
||||||
tt.expect(t, err)
|
tt.expect(t, err)
|
||||||
assert.Equal(t, len(tt.expectedCollectionPaths), len(c.CollectionMap), "collection paths")
|
assert.Equal(t, len(tt.expectedCollectionPaths), len(c.CollectionMap), "collection paths")
|
||||||
|
|||||||
@ -57,7 +57,7 @@ func DataCollections(
|
|||||||
defer close(foldersComplete)
|
defer close(foldersComplete)
|
||||||
|
|
||||||
switch scope.Category().PathType() {
|
switch scope.Category().PathType() {
|
||||||
case path.FilesCategory: // TODO: better category for sp drives, eg: LibrariesCategory
|
case path.LibrariesCategory:
|
||||||
spcs, err := collectLibraries(
|
spcs, err := collectLibraries(
|
||||||
ctx,
|
ctx,
|
||||||
serv,
|
serv,
|
||||||
@ -116,9 +116,9 @@ type folderMatcher struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fm folderMatcher) IsAny() bool {
|
func (fm folderMatcher) IsAny() bool {
|
||||||
return fm.scope.IsAny(selectors.SharePointFolder)
|
return fm.scope.IsAny(selectors.SharePointLibrary)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fm folderMatcher) Matches(dir string) bool {
|
func (fm folderMatcher) Matches(dir string) bool {
|
||||||
return fm.scope.Matches(selectors.SharePointFolder, dir)
|
return fm.scope.Matches(selectors.SharePointLibrary, dir)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,11 +28,11 @@ type testFolderMatcher struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fm testFolderMatcher) IsAny() bool {
|
func (fm testFolderMatcher) IsAny() bool {
|
||||||
return fm.scope.IsAny(selectors.SharePointFolder)
|
return fm.scope.IsAny(selectors.SharePointLibrary)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fm testFolderMatcher) Matches(path string) bool {
|
func (fm testFolderMatcher) Matches(path string) bool {
|
||||||
return fm.scope.Matches(selectors.SharePointFolder, path)
|
return fm.scope.Matches(selectors.SharePointLibrary, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockGraphService struct{}
|
type MockGraphService struct{}
|
||||||
@ -63,7 +63,7 @@ func TestSharePointLibrariesSuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SharePointLibrariesSuite) TestUpdateCollections() {
|
func (suite *SharePointLibrariesSuite) TestUpdateCollections() {
|
||||||
anyFolder := (&selectors.SharePointBackup{}).Folders(selectors.Any(), selectors.Any())[0]
|
anyFolder := (&selectors.SharePointBackup{}).Libraries(selectors.Any(), selectors.Any())[0]
|
||||||
|
|
||||||
const (
|
const (
|
||||||
tenant = "tenant"
|
tenant = "tenant"
|
||||||
|
|||||||
@ -13,11 +13,12 @@ func _() {
|
|||||||
_ = x[ContactsCategory-2]
|
_ = x[ContactsCategory-2]
|
||||||
_ = x[EventsCategory-3]
|
_ = x[EventsCategory-3]
|
||||||
_ = x[FilesCategory-4]
|
_ = x[FilesCategory-4]
|
||||||
|
_ = x[LibrariesCategory-5]
|
||||||
}
|
}
|
||||||
|
|
||||||
const _CategoryType_name = "UnknownCategoryemailcontactseventsfiles"
|
const _CategoryType_name = "UnknownCategoryemailcontactseventsfileslibraries"
|
||||||
|
|
||||||
var _CategoryType_index = [...]uint8{0, 15, 20, 28, 34, 39}
|
var _CategoryType_index = [...]uint8{0, 15, 20, 28, 34, 39, 48}
|
||||||
|
|
||||||
func (i CategoryType) String() string {
|
func (i CategoryType) String() string {
|
||||||
if i < 0 || i >= CategoryType(len(_CategoryType_index)-1) {
|
if i < 0 || i >= CategoryType(len(_CategoryType_index)-1) {
|
||||||
|
|||||||
@ -10,29 +10,44 @@
|
|||||||
//
|
//
|
||||||
// Examples of paths splitting by elements and canonicalization with escaping:
|
// Examples of paths splitting by elements and canonicalization with escaping:
|
||||||
// 1.
|
// 1.
|
||||||
// input path: `this/is/a/path`
|
//
|
||||||
// elements of path: `this`, `is`, `a`, `path`
|
// input path: `this/is/a/path`
|
||||||
|
// elements of path: `this`, `is`, `a`, `path`
|
||||||
|
//
|
||||||
// 2.
|
// 2.
|
||||||
// input path: `this/is\/a/path`
|
//
|
||||||
// elements of path: `this`, `is/a`, `path`
|
// input path: `this/is\/a/path`
|
||||||
|
// elements of path: `this`, `is/a`, `path`
|
||||||
|
//
|
||||||
// 3.
|
// 3.
|
||||||
// input path: `this/is\\/a/path`
|
//
|
||||||
// elements of path: `this`, `is\`, `a`, `path`
|
// input path: `this/is\\/a/path`
|
||||||
|
// elements of path: `this`, `is\`, `a`, `path`
|
||||||
|
//
|
||||||
// 4.
|
// 4.
|
||||||
// input path: `this/is\\\/a/path`
|
//
|
||||||
// elements of path: `this`, `is\/a`, `path`
|
// input path: `this/is\\\/a/path`
|
||||||
|
// elements of path: `this`, `is\/a`, `path`
|
||||||
|
//
|
||||||
// 5.
|
// 5.
|
||||||
// input path: `this/is//a/path`
|
//
|
||||||
// elements of path: `this`, `is`, `a`, `path`
|
// input path: `this/is//a/path`
|
||||||
|
// elements of path: `this`, `is`, `a`, `path`
|
||||||
|
//
|
||||||
// 6.
|
// 6.
|
||||||
// input path: `this/is\//a/path`
|
//
|
||||||
// elements of path: `this`, `is/`, `a`, `path`
|
// input path: `this/is\//a/path`
|
||||||
|
// elements of path: `this`, `is/`, `a`, `path`
|
||||||
|
//
|
||||||
// 7.
|
// 7.
|
||||||
// input path: `this/is/a/path/`
|
//
|
||||||
// elements of path: `this`, `is`, `a`, `path`
|
// input path: `this/is/a/path/`
|
||||||
|
// elements of path: `this`, `is`, `a`, `path`
|
||||||
|
//
|
||||||
// 8.
|
// 8.
|
||||||
// input path: `this/is/a/path\/`
|
//
|
||||||
// elements of path: `this`, `is`, `a`, `path/`
|
// input path: `this/is/a/path\/`
|
||||||
|
// elements of path: `this`, `is`, `a`, `path/`
|
||||||
package path
|
package path
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -307,6 +322,7 @@ func (pb Builder) ToDataLayerOneDrivePath(
|
|||||||
|
|
||||||
func (pb Builder) ToDataLayerSharePointPath(
|
func (pb Builder) ToDataLayerSharePointPath(
|
||||||
tenant, site string,
|
tenant, site string,
|
||||||
|
category CategoryType,
|
||||||
isItem bool,
|
isItem bool,
|
||||||
) (Path, error) {
|
) (Path, error) {
|
||||||
if err := pb.verifyPrefix(tenant, site); err != nil {
|
if err := pb.verifyPrefix(tenant, site); err != nil {
|
||||||
@ -318,10 +334,10 @@ func (pb Builder) ToDataLayerSharePointPath(
|
|||||||
tenant,
|
tenant,
|
||||||
SharePointService.String(),
|
SharePointService.String(),
|
||||||
site,
|
site,
|
||||||
FilesCategory.String(),
|
category.String(),
|
||||||
),
|
),
|
||||||
service: SharePointService,
|
service: SharePointService,
|
||||||
category: FilesCategory,
|
category: category,
|
||||||
hasItem: isItem,
|
hasItem: isItem,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,11 +35,12 @@ type CategoryType int
|
|||||||
|
|
||||||
//go:generate stringer -type=CategoryType -linecomment
|
//go:generate stringer -type=CategoryType -linecomment
|
||||||
const (
|
const (
|
||||||
UnknownCategory CategoryType = iota
|
UnknownCategory CategoryType = iota
|
||||||
EmailCategory // email
|
EmailCategory // email
|
||||||
ContactsCategory // contacts
|
ContactsCategory // contacts
|
||||||
EventsCategory // events
|
EventsCategory // events
|
||||||
FilesCategory // files
|
FilesCategory // files
|
||||||
|
LibrariesCategory // libraries
|
||||||
)
|
)
|
||||||
|
|
||||||
func ToCategoryType(category string) CategoryType {
|
func ToCategoryType(category string) CategoryType {
|
||||||
@ -52,6 +53,8 @@ func ToCategoryType(category string) CategoryType {
|
|||||||
return EventsCategory
|
return EventsCategory
|
||||||
case FilesCategory.String():
|
case FilesCategory.String():
|
||||||
return FilesCategory
|
return FilesCategory
|
||||||
|
case LibrariesCategory.String():
|
||||||
|
return LibrariesCategory
|
||||||
default:
|
default:
|
||||||
return UnknownCategory
|
return UnknownCategory
|
||||||
}
|
}
|
||||||
@ -68,8 +71,8 @@ var serviceCategories = map[ServiceType]map[CategoryType]struct{}{
|
|||||||
FilesCategory: {},
|
FilesCategory: {},
|
||||||
},
|
},
|
||||||
SharePointService: {
|
SharePointService: {
|
||||||
// TODO: need to figure out the service Category(s) for sharepoint.
|
LibrariesCategory: {},
|
||||||
FilesCategory: {},
|
// TODO: Lists
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -104,9 +104,9 @@ var (
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
service: path.SharePointService,
|
service: path.SharePointService,
|
||||||
category: path.FilesCategory,
|
category: path.LibrariesCategory,
|
||||||
pathFunc: func(pb *path.Builder, tenant, user string, isItem bool) (path.Path, error) {
|
pathFunc: func(pb *path.Builder, tenant, site string, isItem bool) (path.Path, error) {
|
||||||
return pb.ToDataLayerSharePointPath(tenant, user, isItem)
|
return pb.ToDataLayerSharePointPath(tenant, site, path.LibrariesCategory, isItem)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -106,11 +106,11 @@ func (suite *ServiceCategoryUnitSuite) TestValidateServiceAndCategory() {
|
|||||||
check: assert.NoError,
|
check: assert.NoError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "SharePointFiles",
|
name: "SharePointLibraries",
|
||||||
service: SharePointService.String(),
|
service: SharePointService.String(),
|
||||||
category: FilesCategory.String(),
|
category: LibrariesCategory.String(),
|
||||||
expectedService: SharePointService,
|
expectedService: SharePointService,
|
||||||
expectedCategory: FilesCategory,
|
expectedCategory: LibrariesCategory,
|
||||||
check: assert.NoError,
|
check: assert.NoError,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -183,16 +183,16 @@ func (s *sharePoint) DiscreteScopes(siteIDs []string) []SharePointScope {
|
|||||||
func (s *sharePoint) Sites(sites []string) []SharePointScope {
|
func (s *sharePoint) Sites(sites []string) []SharePointScope {
|
||||||
scopes := []SharePointScope{}
|
scopes := []SharePointScope{}
|
||||||
|
|
||||||
scopes = append(scopes, makeScope[SharePointScope](SharePointFolder, sites, Any()))
|
scopes = append(scopes, makeScope[SharePointScope](SharePointLibrary, sites, Any()))
|
||||||
|
|
||||||
return scopes
|
return scopes
|
||||||
}
|
}
|
||||||
|
|
||||||
// Folders produces one or more SharePoint folder scopes.
|
// Libraries produces one or more SharePoint library scopes.
|
||||||
// If any slice contains selectors.Any, that slice is reduced to [selectors.Any]
|
// If any slice contains selectors.Any, that slice is reduced to [selectors.Any]
|
||||||
// If any slice contains selectors.None, that slice is reduced to [selectors.None]
|
// If any slice contains selectors.None, that slice is reduced to [selectors.None]
|
||||||
// If any slice is empty, it defaults to [selectors.None]
|
// If any slice is empty, it defaults to [selectors.None]
|
||||||
func (s *sharePoint) Folders(sites, folders []string, opts ...option) []SharePointScope {
|
func (s *sharePoint) Libraries(sites, libraries []string, opts ...option) []SharePointScope {
|
||||||
var (
|
var (
|
||||||
scopes = []SharePointScope{}
|
scopes = []SharePointScope{}
|
||||||
os = append([]option{pathType()}, opts...)
|
os = append([]option{pathType()}, opts...)
|
||||||
@ -200,24 +200,24 @@ func (s *sharePoint) Folders(sites, folders []string, opts ...option) []SharePoi
|
|||||||
|
|
||||||
scopes = append(
|
scopes = append(
|
||||||
scopes,
|
scopes,
|
||||||
makeScope[SharePointScope](SharePointFolder, sites, folders, os...),
|
makeScope[SharePointScope](SharePointLibrary, sites, libraries, os...),
|
||||||
)
|
)
|
||||||
|
|
||||||
return scopes
|
return scopes
|
||||||
}
|
}
|
||||||
|
|
||||||
// Items produces one or more SharePoint item scopes.
|
// LibraryItems produces one or more SharePoint library item scopes.
|
||||||
// If any slice contains selectors.Any, that slice is reduced to [selectors.Any]
|
// If any slice contains selectors.Any, that slice is reduced to [selectors.Any]
|
||||||
// If any slice contains selectors.None, that slice is reduced to [selectors.None]
|
// If any slice contains selectors.None, that slice is reduced to [selectors.None]
|
||||||
// If any slice is empty, it defaults to [selectors.None]
|
// If any slice is empty, it defaults to [selectors.None]
|
||||||
// options are only applied to the folder scopes.
|
// options are only applied to the library scopes.
|
||||||
func (s *sharePoint) Items(sites, folders, items []string, opts ...option) []SharePointScope {
|
func (s *sharePoint) LibraryItems(sites, libraries, items []string, opts ...option) []SharePointScope {
|
||||||
scopes := []SharePointScope{}
|
scopes := []SharePointScope{}
|
||||||
|
|
||||||
scopes = append(
|
scopes = append(
|
||||||
scopes,
|
scopes,
|
||||||
makeScope[SharePointScope](SharePointItem, sites, items).
|
makeScope[SharePointScope](SharePointLibraryItem, sites, items).
|
||||||
set(SharePointFolder, folders, opts...),
|
set(SharePointLibrary, libraries, opts...),
|
||||||
)
|
)
|
||||||
|
|
||||||
return scopes
|
return scopes
|
||||||
@ -233,7 +233,7 @@ func (s *sharePoint) Items(sites, folders, items []string, opts ...option) []Sha
|
|||||||
func (s *sharePoint) WebURL(substring string) []SharePointScope {
|
func (s *sharePoint) WebURL(substring string) []SharePointScope {
|
||||||
return []SharePointScope{
|
return []SharePointScope{
|
||||||
makeFilterScope[SharePointScope](
|
makeFilterScope[SharePointScope](
|
||||||
SharePointItem,
|
SharePointLibraryItem,
|
||||||
SharePointFilterWebURL,
|
SharePointFilterWebURL,
|
||||||
[]string{substring},
|
[]string{substring},
|
||||||
wrapFilter(filters.Less)),
|
wrapFilter(filters.Less)),
|
||||||
@ -254,9 +254,9 @@ var _ categorizer = SharePointCategoryUnknown
|
|||||||
const (
|
const (
|
||||||
SharePointCategoryUnknown sharePointCategory = ""
|
SharePointCategoryUnknown sharePointCategory = ""
|
||||||
// types of data identified by SharePoint
|
// types of data identified by SharePoint
|
||||||
SharePointSite sharePointCategory = "SharePointSite"
|
SharePointSite sharePointCategory = "SharePointSite"
|
||||||
SharePointFolder sharePointCategory = "SharePointFolder"
|
SharePointLibrary sharePointCategory = "SharePointLibrary"
|
||||||
SharePointItem sharePointCategory = "SharePointItem"
|
SharePointLibraryItem sharePointCategory = "SharePointLibraryItem"
|
||||||
|
|
||||||
// filterable topics identified by SharePoint
|
// filterable topics identified by SharePoint
|
||||||
SharePointFilterWebURL sharePointCategory = "SharePointFilterWebURL"
|
SharePointFilterWebURL sharePointCategory = "SharePointFilterWebURL"
|
||||||
@ -264,9 +264,9 @@ const (
|
|||||||
|
|
||||||
// sharePointLeafProperties describes common metadata of the leaf categories
|
// sharePointLeafProperties describes common metadata of the leaf categories
|
||||||
var sharePointLeafProperties = map[categorizer]leafProperty{
|
var sharePointLeafProperties = map[categorizer]leafProperty{
|
||||||
SharePointItem: {
|
SharePointLibraryItem: {
|
||||||
pathKeys: []categorizer{SharePointSite, SharePointFolder, SharePointItem},
|
pathKeys: []categorizer{SharePointSite, SharePointLibrary, SharePointLibraryItem},
|
||||||
pathType: path.FilesCategory,
|
pathType: path.LibrariesCategory,
|
||||||
},
|
},
|
||||||
SharePointSite: { // the root category must be represented, even though it isn't a leaf
|
SharePointSite: { // the root category must be represented, even though it isn't a leaf
|
||||||
pathKeys: []categorizer{SharePointSite},
|
pathKeys: []categorizer{SharePointSite},
|
||||||
@ -285,9 +285,9 @@ func (c sharePointCategory) String() string {
|
|||||||
// Ex: ServiceUser.leafCat() => ServiceUser
|
// Ex: ServiceUser.leafCat() => ServiceUser
|
||||||
func (c sharePointCategory) leafCat() categorizer {
|
func (c sharePointCategory) leafCat() categorizer {
|
||||||
switch c {
|
switch c {
|
||||||
case SharePointFolder, SharePointItem,
|
case SharePointLibrary, SharePointLibraryItem,
|
||||||
SharePointFilterWebURL:
|
SharePointFilterWebURL:
|
||||||
return SharePointItem
|
return SharePointLibraryItem
|
||||||
}
|
}
|
||||||
|
|
||||||
return c
|
return c
|
||||||
@ -305,8 +305,7 @@ func (c sharePointCategory) unknownCat() categorizer {
|
|||||||
|
|
||||||
// isLeaf is true if the category is a SharePointItem category.
|
// isLeaf is true if the category is a SharePointItem category.
|
||||||
func (c sharePointCategory) isLeaf() bool {
|
func (c sharePointCategory) isLeaf() bool {
|
||||||
// return c == c.leafCat()??
|
return c == c.leafCat()
|
||||||
return c == SharePointItem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pathValues transforms a path to a map of identified properties.
|
// pathValues transforms a path to a map of identified properties.
|
||||||
@ -316,9 +315,9 @@ func (c sharePointCategory) isLeaf() bool {
|
|||||||
// => {spSite: siteID, spFolder: folder, spItemID: itemID}
|
// => {spSite: siteID, spFolder: folder, spItemID: itemID}
|
||||||
func (c sharePointCategory) pathValues(p path.Path) map[categorizer]string {
|
func (c sharePointCategory) pathValues(p path.Path) map[categorizer]string {
|
||||||
return map[categorizer]string{
|
return map[categorizer]string{
|
||||||
SharePointSite: p.ResourceOwner(),
|
SharePointSite: p.ResourceOwner(),
|
||||||
SharePointFolder: p.Folder(),
|
SharePointLibrary: p.Folder(),
|
||||||
SharePointItem: p.Item(),
|
SharePointLibraryItem: p.Item(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,7 +389,7 @@ func (s SharePointScope) Get(cat sharePointCategory) []string {
|
|||||||
// sets a value by category to the scope. Only intended for internal use.
|
// sets a value by category to the scope. Only intended for internal use.
|
||||||
func (s SharePointScope) set(cat sharePointCategory, v []string, opts ...option) SharePointScope {
|
func (s SharePointScope) set(cat sharePointCategory, v []string, opts ...option) SharePointScope {
|
||||||
os := []option{}
|
os := []option{}
|
||||||
if cat == SharePointFolder {
|
if cat == SharePointLibrary {
|
||||||
os = append(os, pathType())
|
os = append(os, pathType())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,10 +400,10 @@ func (s SharePointScope) set(cat sharePointCategory, v []string, opts ...option)
|
|||||||
func (s SharePointScope) setDefaults() {
|
func (s SharePointScope) setDefaults() {
|
||||||
switch s.Category() {
|
switch s.Category() {
|
||||||
case SharePointSite:
|
case SharePointSite:
|
||||||
s[SharePointFolder.String()] = passAny
|
s[SharePointLibrary.String()] = passAny
|
||||||
s[SharePointItem.String()] = passAny
|
s[SharePointLibraryItem.String()] = passAny
|
||||||
case SharePointFolder:
|
case SharePointLibrary:
|
||||||
s[SharePointItem.String()] = passAny
|
s[SharePointLibraryItem.String()] = passAny
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,8 +441,8 @@ func (s sharePoint) Reduce(ctx context.Context, deets *details.Details) *details
|
|||||||
deets,
|
deets,
|
||||||
s.Selector,
|
s.Selector,
|
||||||
map[path.CategoryType]sharePointCategory{
|
map[path.CategoryType]sharePointCategory{
|
||||||
// TODO: need to figure out the path Category(s) for sharepoint.
|
path.LibrariesCategory: SharePointLibraryItem,
|
||||||
path.FilesCategory: SharePointItem,
|
// TODO: list category type
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -181,9 +181,9 @@ func (suite *SharePointSelectorSuite) TestToSharePointRestore() {
|
|||||||
|
|
||||||
func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
|
func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
|
||||||
var (
|
var (
|
||||||
item = stubRepoRef(path.SharePointService, path.FilesCategory, "uid", "/folderA/folderB", "item")
|
item = stubRepoRef(path.SharePointService, path.LibrariesCategory, "uid", "/folderA/folderB", "item")
|
||||||
item2 = stubRepoRef(path.SharePointService, path.FilesCategory, "uid", "/folderA/folderC", "item2")
|
item2 = stubRepoRef(path.SharePointService, path.LibrariesCategory, "uid", "/folderA/folderC", "item2")
|
||||||
item3 = stubRepoRef(path.SharePointService, path.FilesCategory, "uid", "/folderD/folderE", "item3")
|
item3 = stubRepoRef(path.SharePointService, path.LibrariesCategory, "uid", "/folderD/folderE", "item3")
|
||||||
)
|
)
|
||||||
|
|
||||||
deets := &details.Details{
|
deets := &details.Details{
|
||||||
@ -242,7 +242,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
|
|||||||
deets,
|
deets,
|
||||||
func() *SharePointRestore {
|
func() *SharePointRestore {
|
||||||
odr := NewSharePointRestore()
|
odr := NewSharePointRestore()
|
||||||
odr.Include(odr.Items(Any(), Any(), []string{"item2"}))
|
odr.Include(odr.LibraryItems(Any(), Any(), []string{"item2"}))
|
||||||
return odr
|
return odr
|
||||||
},
|
},
|
||||||
arr(item2),
|
arr(item2),
|
||||||
@ -252,7 +252,7 @@ func (suite *SharePointSelectorSuite) TestSharePointRestore_Reduce() {
|
|||||||
deets,
|
deets,
|
||||||
func() *SharePointRestore {
|
func() *SharePointRestore {
|
||||||
odr := NewSharePointRestore()
|
odr := NewSharePointRestore()
|
||||||
odr.Include(odr.Folders([]string{"uid"}, []string{"folderA/folderB", "folderA/folderC"}))
|
odr.Include(odr.Libraries([]string{"uid"}, []string{"folderA/folderB", "folderA/folderC"}))
|
||||||
return odr
|
return odr
|
||||||
},
|
},
|
||||||
arr(item, item2),
|
arr(item, item2),
|
||||||
@ -275,16 +275,16 @@ func (suite *SharePointSelectorSuite) TestSharePointCategory_PathValues() {
|
|||||||
t := suite.T()
|
t := suite.T()
|
||||||
|
|
||||||
pathBuilder := path.Builder{}.Append("dir1", "dir2", "item")
|
pathBuilder := path.Builder{}.Append("dir1", "dir2", "item")
|
||||||
itemPath, err := pathBuilder.ToDataLayerSharePointPath("tenant", "site", true)
|
itemPath, err := pathBuilder.ToDataLayerSharePointPath("tenant", "site", path.LibrariesCategory, true)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
expected := map[categorizer]string{
|
expected := map[categorizer]string{
|
||||||
SharePointSite: "site",
|
SharePointSite: "site",
|
||||||
SharePointFolder: "dir1/dir2",
|
SharePointLibrary: "dir1/dir2",
|
||||||
SharePointItem: "item",
|
SharePointLibraryItem: "item",
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, expected, SharePointItem.pathValues(itemPath))
|
assert.Equal(t, expected, SharePointLibraryItem.pathValues(itemPath))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SharePointSelectorSuite) TestSharePointScope_MatchesInfo() {
|
func (suite *SharePointSelectorSuite) TestSharePointScope_MatchesInfo() {
|
||||||
@ -325,9 +325,9 @@ func (suite *SharePointSelectorSuite) TestCategory_PathType() {
|
|||||||
}{
|
}{
|
||||||
{SharePointCategoryUnknown, path.UnknownCategory},
|
{SharePointCategoryUnknown, path.UnknownCategory},
|
||||||
{SharePointSite, path.UnknownCategory},
|
{SharePointSite, path.UnknownCategory},
|
||||||
{SharePointFolder, path.FilesCategory},
|
{SharePointLibrary, path.LibrariesCategory},
|
||||||
{SharePointItem, path.FilesCategory},
|
{SharePointLibraryItem, path.LibrariesCategory},
|
||||||
{SharePointFilterWebURL, path.FilesCategory},
|
{SharePointFilterWebURL, path.LibrariesCategory},
|
||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
suite.T().Run(test.cat.String(), func(t *testing.T) {
|
suite.T().Run(test.cat.String(), func(t *testing.T) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user