populate sharepoint selectors with scopes (#1910)
## Description On backup create, sharepoint selectors also need scopes, or else they do nothing. ## Does this PR need a docs update or release note? - [x] ⛔ No ## Type of change - [x] 🐛 Bugfix ## Issue(s) * #1908 ## Test Plan - [x] 💪 Manual - [x] ⚡ Unit test
This commit is contained in:
parent
d3573d12dc
commit
8fa440e277
@ -273,9 +273,15 @@ func sharePointBackupCreateSelectors(
|
|||||||
sites, weburls []string,
|
sites, weburls []string,
|
||||||
gc *connector.GraphConnector,
|
gc *connector.GraphConnector,
|
||||||
) (*selectors.SharePointBackup, error) {
|
) (*selectors.SharePointBackup, error) {
|
||||||
|
if len(sites) == 0 && len(weburls) == 0 {
|
||||||
|
return selectors.NewSharePointBackup(selectors.None()), nil
|
||||||
|
}
|
||||||
|
|
||||||
for _, site := range sites {
|
for _, site := range sites {
|
||||||
if site == utils.Wildcard {
|
if site == utils.Wildcard {
|
||||||
sel := selectors.NewSharePointBackup(selectors.Any())
|
sel := selectors.NewSharePointBackup(selectors.Any())
|
||||||
|
sel.Include(sel.Sites(selectors.Any()))
|
||||||
|
|
||||||
return sel, nil
|
return sel, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -283,6 +289,8 @@ func sharePointBackupCreateSelectors(
|
|||||||
for _, wURL := range weburls {
|
for _, wURL := range weburls {
|
||||||
if wURL == utils.Wildcard {
|
if wURL == utils.Wildcard {
|
||||||
sel := selectors.NewSharePointBackup(selectors.Any())
|
sel := selectors.NewSharePointBackup(selectors.Any())
|
||||||
|
sel.Include(sel.Sites(selectors.Any()))
|
||||||
|
|
||||||
return sel, nil
|
return sel, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,7 +300,10 @@ func sharePointBackupCreateSelectors(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return selectors.NewSharePointBackup(union), nil
|
sel := selectors.NewSharePointBackup(union)
|
||||||
|
sel.Include(sel.Sites(union))
|
||||||
|
|
||||||
|
return sel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -112,10 +112,11 @@ func (suite *SharePointSuite) TestSharePointBackupCreateSelectors() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
site []string
|
site []string
|
||||||
weburl []string
|
weburl []string
|
||||||
expect []string
|
expect []string
|
||||||
|
expectScopesLen int
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no sites or urls",
|
name: "no sites or urls",
|
||||||
@ -128,48 +129,56 @@ func (suite *SharePointSuite) TestSharePointBackupCreateSelectors() {
|
|||||||
expect: selectors.None(),
|
expect: selectors.None(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "site wildcard",
|
name: "site wildcard",
|
||||||
site: []string{utils.Wildcard},
|
site: []string{utils.Wildcard},
|
||||||
expect: selectors.Any(),
|
expect: selectors.Any(),
|
||||||
|
expectScopesLen: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "url wildcard",
|
name: "url wildcard",
|
||||||
weburl: []string{utils.Wildcard},
|
weburl: []string{utils.Wildcard},
|
||||||
expect: selectors.Any(),
|
expect: selectors.Any(),
|
||||||
|
expectScopesLen: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "sites",
|
name: "sites",
|
||||||
site: []string{"id_1", "id_2"},
|
site: []string{"id_1", "id_2"},
|
||||||
expect: []string{"id_1", "id_2"},
|
expect: []string{"id_1", "id_2"},
|
||||||
|
expectScopesLen: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "urls",
|
name: "urls",
|
||||||
weburl: []string{"url_1", "url_2"},
|
weburl: []string{"url_1", "url_2"},
|
||||||
expect: []string{"id_1", "id_2"},
|
expect: []string{"id_1", "id_2"},
|
||||||
|
expectScopesLen: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "mix sites and urls",
|
name: "mix sites and urls",
|
||||||
site: []string{"id_1"},
|
site: []string{"id_1"},
|
||||||
weburl: []string{"url_2"},
|
weburl: []string{"url_2"},
|
||||||
expect: []string{"id_1", "id_2"},
|
expect: []string{"id_1", "id_2"},
|
||||||
|
expectScopesLen: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "duplicate sites and urls",
|
name: "duplicate sites and urls",
|
||||||
site: []string{"id_1", "id_2"},
|
site: []string{"id_1", "id_2"},
|
||||||
weburl: []string{"url_1", "url_2"},
|
weburl: []string{"url_1", "url_2"},
|
||||||
expect: []string{"id_1", "id_2"},
|
expect: []string{"id_1", "id_2"},
|
||||||
|
expectScopesLen: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "unnecessary site wildcard",
|
name: "unnecessary site wildcard",
|
||||||
site: []string{"id_1", utils.Wildcard},
|
site: []string{"id_1", utils.Wildcard},
|
||||||
weburl: []string{"url_1", "url_2"},
|
weburl: []string{"url_1", "url_2"},
|
||||||
expect: selectors.Any(),
|
expect: selectors.Any(),
|
||||||
|
expectScopesLen: 2,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "unnecessary url wildcard",
|
name: "unnecessary url wildcard",
|
||||||
site: []string{"id_1", "id_2"},
|
site: []string{"id_1", "id_2"},
|
||||||
weburl: []string{"url_1", utils.Wildcard},
|
weburl: []string{"url_1", utils.Wildcard},
|
||||||
expect: selectors.Any(),
|
expect: selectors.Any(),
|
||||||
|
expectScopesLen: 2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
@ -180,13 +189,14 @@ func (suite *SharePointSuite) TestSharePointBackupCreateSelectors() {
|
|||||||
sel, err := sharePointBackupCreateSelectors(ctx, test.site, test.weburl, gc)
|
sel, err := sharePointBackupCreateSelectors(ctx, test.site, test.weburl, gc)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
if len(sel.Scopes()) == 0 {
|
scopes := sel.Scopes()
|
||||||
|
assert.Len(t, scopes, test.expectScopesLen)
|
||||||
|
|
||||||
|
if test.expectScopesLen == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
scope := sel.Scopes()[0]
|
targetSites := scopes[0].Get(selectors.SharePointSite)
|
||||||
targetSites := scope.Get(selectors.SharePointSite)
|
|
||||||
|
|
||||||
assert.ElementsMatch(t, test.expect, targetSites)
|
assert.ElementsMatch(t, test.expect, targetSites)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user