GC: Reduce the amount of folders upon restore (#637)
* Issue #595: All collections with the same `fullPath` name are to be stored within the same folder.
This commit is contained in:
parent
6e7335cc4d
commit
3b9c8e284c
@ -250,16 +250,18 @@ func (gc *GraphConnector) RestoreMessages(ctx context.Context, dcs []data.Collec
|
||||
policy := control.Copy // TODO policy to be updated from external source after completion of refactoring
|
||||
|
||||
for _, dc := range dcs {
|
||||
directory := strings.Join(dc.FullPath(), "")
|
||||
user := dc.FullPath()[1]
|
||||
items := dc.Items()
|
||||
pathCounter[strings.Join(dc.FullPath(), "")] = true
|
||||
if _, ok := pathCounter[directory]; !ok {
|
||||
pathCounter[directory] = true
|
||||
if policy == control.Copy {
|
||||
folderID, errs = exchange.GetCopyRestoreFolder(&gc.graphService, user)
|
||||
if errs != nil {
|
||||
return errs
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
var exit bool
|
||||
for !exit {
|
||||
select {
|
||||
|
||||
@ -224,15 +224,28 @@ func (suite *GraphConnectorIntegrationSuite) TestEventsSerializationRegression()
|
||||
}
|
||||
|
||||
// TestRestoreMessages uses mock data to ensure GraphConnector
|
||||
// is able to restore a single messageable item to a Mailbox.
|
||||
// is able to restore a several messageable item to a Mailbox.
|
||||
// The result should be all successful items restored within the same folder.
|
||||
func (suite *GraphConnectorIntegrationSuite) TestRestoreMessages() {
|
||||
user := tester.M365UserID(suite.T())
|
||||
t := suite.T()
|
||||
connector := loadConnector(t)
|
||||
user := tester.M365UserID(t)
|
||||
if len(user) == 0 {
|
||||
suite.T().Skip("Environment not configured: missing m365 test user")
|
||||
}
|
||||
|
||||
collection := make([]data.Collection, 0)
|
||||
for i := 0; i < 3; i++ {
|
||||
mdc := mockconnector.NewMockExchangeCollection([]string{"tenant", user, mailCategory, "Inbox"}, 1)
|
||||
err := suite.connector.RestoreMessages(context.Background(), []data.Collection{mdc})
|
||||
collection = append(collection, mdc)
|
||||
}
|
||||
|
||||
err := connector.RestoreMessages(context.Background(), collection)
|
||||
assert.NoError(suite.T(), err)
|
||||
status := connector.AwaitStatus()
|
||||
assert.NotNil(t, status)
|
||||
assert.Equal(t, status.ObjectCount, status.Successful)
|
||||
assert.Equal(t, status.FolderCount, 1)
|
||||
}
|
||||
|
||||
// TestGraphConnector_SingleMailFolderCollectionQuery verifies single folder support
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
type ConnectorOperationStatus struct {
|
||||
lastOperation Operation
|
||||
ObjectCount int
|
||||
folderCount int
|
||||
FolderCount int
|
||||
Successful int
|
||||
errorCount int
|
||||
incomplete bool
|
||||
@ -42,7 +42,7 @@ func CreateStatus(
|
||||
status := ConnectorOperationStatus{
|
||||
lastOperation: op,
|
||||
ObjectCount: objects,
|
||||
folderCount: folders,
|
||||
FolderCount: folders,
|
||||
Successful: success,
|
||||
errorCount: numErr,
|
||||
incomplete: hasErrors,
|
||||
@ -60,7 +60,7 @@ func CreateStatus(
|
||||
|
||||
func (cos *ConnectorOperationStatus) String() string {
|
||||
message := fmt.Sprintf("Action: %s performed on %d of %d objects within %d directories.", cos.lastOperation.String(),
|
||||
cos.Successful, cos.ObjectCount, cos.folderCount)
|
||||
cos.Successful, cos.ObjectCount, cos.FolderCount)
|
||||
if cos.incomplete {
|
||||
message += " " + cos.incompleteReason
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user