Fxi issues with GetMetadataPaths (#4252)
<!-- PR description--> --- #### 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 <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [x] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #<issue> #### Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E
This commit is contained in:
parent
14416094e6
commit
636be4feed
@ -204,8 +204,8 @@ func (ctrl *Controller) GetMetadataPaths(
|
|||||||
for _, reason := range man.Reasons {
|
for _, reason := range man.Reasons {
|
||||||
filePaths := [][]string{}
|
filePaths := [][]string{}
|
||||||
|
|
||||||
switch reason.Service() {
|
switch true {
|
||||||
case path.GroupsService:
|
case reason.Service() == path.GroupsService && reason.Category() == path.LibrariesCategory:
|
||||||
filePaths, err = groups.MetadataFiles(ctx, reason, r, man.ID, errs)
|
filePaths, err = groups.MetadataFiles(ctx, reason, r, man.ID, errs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
package operations
|
package operations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
@ -11,13 +13,16 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/data"
|
"github.com/alcionai/corso/src/internal/data"
|
||||||
|
dataMock "github.com/alcionai/corso/src/internal/data/mock"
|
||||||
"github.com/alcionai/corso/src/internal/kopia"
|
"github.com/alcionai/corso/src/internal/kopia"
|
||||||
"github.com/alcionai/corso/src/internal/m365"
|
"github.com/alcionai/corso/src/internal/m365"
|
||||||
|
odConsts "github.com/alcionai/corso/src/internal/m365/service/onedrive/consts"
|
||||||
"github.com/alcionai/corso/src/internal/model"
|
"github.com/alcionai/corso/src/internal/model"
|
||||||
"github.com/alcionai/corso/src/internal/operations/inject/mock"
|
"github.com/alcionai/corso/src/internal/operations/inject/mock"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/backup"
|
"github.com/alcionai/corso/src/pkg/backup"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/identity"
|
"github.com/alcionai/corso/src/pkg/backup/identity"
|
||||||
|
"github.com/alcionai/corso/src/pkg/backup/metadata"
|
||||||
"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/path"
|
||||||
)
|
)
|
||||||
@ -87,6 +92,8 @@ func (suite *OperationsManifestsUnitSuite) TestGetMetadataPaths() {
|
|||||||
tid = "tenantid"
|
tid = "tenantid"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
t := suite.T()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
emailPath = makeMetadataBasePath(
|
emailPath = makeMetadataBasePath(
|
||||||
suite.T(),
|
suite.T(),
|
||||||
@ -100,13 +107,56 @@ func (suite *OperationsManifestsUnitSuite) TestGetMetadataPaths() {
|
|||||||
path.ExchangeService,
|
path.ExchangeService,
|
||||||
ro,
|
ro,
|
||||||
path.ContactsCategory)
|
path.ContactsCategory)
|
||||||
|
spLibsPath = makeMetadataBasePath(
|
||||||
|
suite.T(),
|
||||||
|
tid,
|
||||||
|
path.SharePointService,
|
||||||
|
ro,
|
||||||
|
path.LibrariesCategory)
|
||||||
|
messagesPath = makeMetadataBasePath(
|
||||||
|
suite.T(),
|
||||||
|
tid,
|
||||||
|
path.GroupsService,
|
||||||
|
ro,
|
||||||
|
path.ChannelMessagesCategory)
|
||||||
|
groupLibsPath = makeMetadataBasePath(
|
||||||
|
suite.T(),
|
||||||
|
tid,
|
||||||
|
path.GroupsService,
|
||||||
|
ro,
|
||||||
|
path.LibrariesCategory)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
groupLibsSitesPath, err := groupLibsPath.Append(false, odConsts.SitesPathDir)
|
||||||
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
|
groupLibsSite1Path, err := groupLibsSitesPath.Append(false, "site1")
|
||||||
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
|
groupLibsSite2Path, err := groupLibsSitesPath.Append(false, "site2")
|
||||||
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
|
getRestorePaths := func(t *testing.T, base path.Path, paths []string) []path.RestorePaths {
|
||||||
|
ps := []path.RestorePaths{}
|
||||||
|
|
||||||
|
for _, f := range paths {
|
||||||
|
p, err := base.AppendItem(f)
|
||||||
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
|
ps = append(ps, path.RestorePaths{StoragePath: p, RestorePath: base})
|
||||||
|
}
|
||||||
|
|
||||||
|
return ps
|
||||||
|
}
|
||||||
|
|
||||||
table := []struct {
|
table := []struct {
|
||||||
name string
|
name string
|
||||||
manID string
|
manID string
|
||||||
reasons []identity.Reasoner
|
reasons []identity.Reasoner
|
||||||
|
preFetchPaths []string
|
||||||
|
preFetchCollection []data.RestoreCollection
|
||||||
expectPaths func(*testing.T, []string) []path.Path
|
expectPaths func(*testing.T, []string) []path.Path
|
||||||
|
restorePaths []path.RestorePaths
|
||||||
expectErr error
|
expectErr error
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -115,6 +165,7 @@ func (suite *OperationsManifestsUnitSuite) TestGetMetadataPaths() {
|
|||||||
reasons: []identity.Reasoner{
|
reasons: []identity.Reasoner{
|
||||||
kopia.NewReason(tid, ro, path.ExchangeService, path.EmailCategory),
|
kopia.NewReason(tid, ro, path.ExchangeService, path.EmailCategory),
|
||||||
},
|
},
|
||||||
|
preFetchPaths: []string{},
|
||||||
expectPaths: func(t *testing.T, files []string) []path.Path {
|
expectPaths: func(t *testing.T, files []string) []path.Path {
|
||||||
ps := make([]path.Path, 0, len(files))
|
ps := make([]path.Path, 0, len(files))
|
||||||
|
|
||||||
@ -126,6 +177,7 @@ func (suite *OperationsManifestsUnitSuite) TestGetMetadataPaths() {
|
|||||||
|
|
||||||
return ps
|
return ps
|
||||||
},
|
},
|
||||||
|
restorePaths: getRestorePaths(t, emailPath, metadata.AllMetadataFileNames()),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple reasons",
|
name: "multiple reasons",
|
||||||
@ -134,6 +186,7 @@ func (suite *OperationsManifestsUnitSuite) TestGetMetadataPaths() {
|
|||||||
kopia.NewReason(tid, ro, path.ExchangeService, path.EmailCategory),
|
kopia.NewReason(tid, ro, path.ExchangeService, path.EmailCategory),
|
||||||
kopia.NewReason(tid, ro, path.ExchangeService, path.ContactsCategory),
|
kopia.NewReason(tid, ro, path.ExchangeService, path.ContactsCategory),
|
||||||
},
|
},
|
||||||
|
preFetchPaths: []string{},
|
||||||
expectPaths: func(t *testing.T, files []string) []path.Path {
|
expectPaths: func(t *testing.T, files []string) []path.Path {
|
||||||
ps := make([]path.Path, 0, len(files))
|
ps := make([]path.Path, 0, len(files))
|
||||||
|
|
||||||
@ -148,6 +201,81 @@ func (suite *OperationsManifestsUnitSuite) TestGetMetadataPaths() {
|
|||||||
|
|
||||||
return ps
|
return ps
|
||||||
},
|
},
|
||||||
|
restorePaths: append(
|
||||||
|
getRestorePaths(t, emailPath, metadata.AllMetadataFileNames()),
|
||||||
|
getRestorePaths(t, contactPath, metadata.AllMetadataFileNames())...),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "single reason sp libraries",
|
||||||
|
manID: "single-sp-libraries",
|
||||||
|
reasons: []identity.Reasoner{
|
||||||
|
kopia.NewReason(tid, ro, path.SharePointService, path.LibrariesCategory),
|
||||||
|
},
|
||||||
|
preFetchPaths: []string{},
|
||||||
|
expectPaths: func(t *testing.T, files []string) []path.Path {
|
||||||
|
ps := make([]path.Path, 0, len(files))
|
||||||
|
|
||||||
|
for _, f := range files {
|
||||||
|
p, err := spLibsPath.AppendItem(f)
|
||||||
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
ps = append(ps, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ps
|
||||||
|
},
|
||||||
|
restorePaths: getRestorePaths(t, spLibsPath, metadata.AllMetadataFileNames()),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "single reason groups messages",
|
||||||
|
manID: "single-groups-messages",
|
||||||
|
reasons: []identity.Reasoner{
|
||||||
|
kopia.NewReason(tid, ro, path.GroupsService, path.ChannelMessagesCategory),
|
||||||
|
},
|
||||||
|
preFetchPaths: []string{},
|
||||||
|
expectPaths: func(t *testing.T, files []string) []path.Path {
|
||||||
|
ps := make([]path.Path, 0, len(files))
|
||||||
|
|
||||||
|
for _, f := range files {
|
||||||
|
p, err := messagesPath.AppendItem(f)
|
||||||
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
ps = append(ps, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ps
|
||||||
|
},
|
||||||
|
restorePaths: getRestorePaths(t, messagesPath, metadata.AllMetadataFileNames()),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "single reason groups libraries",
|
||||||
|
manID: "single-groups-libraries",
|
||||||
|
reasons: []identity.Reasoner{
|
||||||
|
kopia.NewReason(tid, ro, path.GroupsService, path.LibrariesCategory),
|
||||||
|
},
|
||||||
|
preFetchPaths: []string{"previouspath"},
|
||||||
|
expectPaths: func(t *testing.T, files []string) []path.Path {
|
||||||
|
ps := make([]path.Path, 0, len(files))
|
||||||
|
|
||||||
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
for _, f := range files {
|
||||||
|
p, err := groupLibsSitesPath.AppendItem(f)
|
||||||
|
assert.NoError(t, err, clues.ToCore(err))
|
||||||
|
ps = append(ps, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ps
|
||||||
|
},
|
||||||
|
restorePaths: append(
|
||||||
|
getRestorePaths(t, groupLibsSite1Path, metadata.AllMetadataFileNames()),
|
||||||
|
getRestorePaths(t, groupLibsSite2Path, metadata.AllMetadataFileNames())...),
|
||||||
|
preFetchCollection: []data.RestoreCollection{dataMock.Collection{
|
||||||
|
ItemData: []data.Item{
|
||||||
|
&dataMock.Item{
|
||||||
|
ItemID: "previouspath",
|
||||||
|
Reader: io.NopCloser(bytes.NewReader(
|
||||||
|
[]byte(`{"site1": "/path/does/not/matter", "site2": "/path/does/not/matter"}`))),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range table {
|
for _, test := range table {
|
||||||
@ -157,9 +285,9 @@ func (suite *OperationsManifestsUnitSuite) TestGetMetadataPaths() {
|
|||||||
ctx, flush := tester.NewContext(t)
|
ctx, flush := tester.NewContext(t)
|
||||||
defer flush()
|
defer flush()
|
||||||
|
|
||||||
paths := test.expectPaths(t, []string{"delta", "previouspath"})
|
paths := test.expectPaths(t, test.preFetchPaths)
|
||||||
|
|
||||||
mr := mockRestoreProducer{err: test.expectErr}
|
mr := mockRestoreProducer{err: test.expectErr, colls: test.preFetchCollection}
|
||||||
mr.buildRestoreFunc(t, test.manID, paths)
|
mr.buildRestoreFunc(t, test.manID, paths)
|
||||||
|
|
||||||
man := kopia.ManifestEntry{
|
man := kopia.ManifestEntry{
|
||||||
@ -168,8 +296,9 @@ func (suite *OperationsManifestsUnitSuite) TestGetMetadataPaths() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
controller := m365.Controller{}
|
controller := m365.Controller{}
|
||||||
_, err := controller.GetMetadataPaths(ctx, &mr, man, fault.New(true))
|
pths, err := controller.GetMetadataPaths(ctx, &mr, man, fault.New(true))
|
||||||
assert.ErrorIs(t, err, test.expectErr, clues.ToCore(err))
|
assert.ErrorIs(t, err, test.expectErr, clues.ToCore(err))
|
||||||
|
assert.ElementsMatch(t, test.restorePaths, pths, "restore paths")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user