check subfolders email counts in exchange (#2900)
<!-- PR description--> check that no of emails in all subfolders is equivalent in restores. #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [ ] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [ ] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 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
This commit is contained in:
parent
d1ce661b8f
commit
a9c4479a7b
@ -46,13 +46,21 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkEmailRestoration(client *msgraphsdk.GraphServiceClient, testUser, folderName string, startTime time.Time) {
|
// checkEmailRestoration verifies that the emails count in restored folder is equivalent to
|
||||||
|
// emails in actual m365 account
|
||||||
|
func checkEmailRestoration(
|
||||||
|
client *msgraphsdk.GraphServiceClient,
|
||||||
|
testUser,
|
||||||
|
folderName string,
|
||||||
|
startTime time.Time,
|
||||||
|
) {
|
||||||
var (
|
var (
|
||||||
messageCount = make(map[string]int32)
|
messageCount = make(map[string]int32)
|
||||||
restoreFolder models.MailFolderable
|
restoreFolder models.MailFolderable
|
||||||
)
|
)
|
||||||
|
|
||||||
builder := client.UsersById(testUser).MailFolders()
|
user := client.UsersById(testUser)
|
||||||
|
builder := user.MailFolders()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
result, err := builder.Get(context.Background(), nil)
|
result, err := builder.Get(context.Background(), nil)
|
||||||
@ -64,7 +72,10 @@ func checkEmailRestoration(client *msgraphsdk.GraphServiceClient, testUser, fold
|
|||||||
res := result.GetValue()
|
res := result.GetValue()
|
||||||
|
|
||||||
for _, r := range res {
|
for _, r := range res {
|
||||||
name := *r.GetDisplayName()
|
name, ok := ptr.ValOK(r.GetDisplayName())
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
var rStartTime time.Time
|
var rStartTime time.Time
|
||||||
|
|
||||||
@ -82,7 +93,9 @@ func checkEmailRestoration(client *msgraphsdk.GraphServiceClient, testUser, fold
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
messageCount[*r.GetDisplayName()] = *r.GetTotalItemCount()
|
getAllSubFolder(client, testUser, r, name, messageCount)
|
||||||
|
|
||||||
|
messageCount[name], _ = ptr.ValOK(r.GetTotalItemCount())
|
||||||
}
|
}
|
||||||
|
|
||||||
link, ok := ptr.ValOK(result.GetOdataNextLink())
|
link, ok := ptr.ValOK(result.GetOdataNextLink())
|
||||||
@ -93,8 +106,13 @@ func checkEmailRestoration(client *msgraphsdk.GraphServiceClient, testUser, fold
|
|||||||
builder = users.NewItemMailFoldersRequestBuilder(link, client.GetAdapter())
|
builder = users.NewItemMailFoldersRequestBuilder(link, client.GetAdapter())
|
||||||
}
|
}
|
||||||
|
|
||||||
user := client.UsersById(testUser)
|
folderID, ok := ptr.ValOK(restoreFolder.GetId())
|
||||||
folder := user.MailFoldersById(*restoreFolder.GetId())
|
if !ok {
|
||||||
|
fmt.Printf("can't find ID of restore folder")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
folder := user.MailFoldersById(folderID)
|
||||||
|
|
||||||
childFolder, err := folder.ChildFolders().Get(context.Background(), nil)
|
childFolder, err := folder.ChildFolders().Get(context.Background(), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -103,15 +121,113 @@ func checkEmailRestoration(client *msgraphsdk.GraphServiceClient, testUser, fold
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, restore := range childFolder.GetValue() {
|
for _, restore := range childFolder.GetValue() {
|
||||||
if messageCount[*restore.GetDisplayName()] != *restore.GetTotalItemCount() {
|
restoreDisplayName, ok := ptr.ValOK(restore.GetDisplayName())
|
||||||
fmt.Println("Restore was not succesfull for: ",
|
if !ok {
|
||||||
*restore.GetDisplayName(),
|
continue
|
||||||
"Folder count: ",
|
}
|
||||||
messageCount[*restore.GetDisplayName()],
|
|
||||||
"Restore count: ",
|
restoreItemCount, _ := ptr.ValOK(restore.GetTotalItemCount())
|
||||||
*restore.GetTotalItemCount())
|
|
||||||
|
if messageCount[restoreDisplayName] != restoreItemCount {
|
||||||
|
fmt.Println("Restore was not succesfull for: ", restoreDisplayName,
|
||||||
|
"Folder count: ", messageCount[restoreDisplayName],
|
||||||
|
"Restore count: ", restoreItemCount)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkAllSubFolder(client, testUser, restore, restoreDisplayName, messageCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getAllSubFolder will recursively check for all subfolders and get the corresponding
|
||||||
|
// email count.
|
||||||
|
func getAllSubFolder(
|
||||||
|
client *msgraphsdk.GraphServiceClient,
|
||||||
|
testUser string,
|
||||||
|
r models.MailFolderable,
|
||||||
|
parentFolder string,
|
||||||
|
messageCount map[string]int32,
|
||||||
|
) {
|
||||||
|
folderID, ok := ptr.ValOK(r.GetId())
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
fmt.Println("unable to get sub folder ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user := client.UsersById(testUser)
|
||||||
|
folder := user.MailFoldersById(folderID)
|
||||||
|
|
||||||
|
childFolder, err := folder.ChildFolders().Get(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error getting the drive: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, child := range childFolder.GetValue() {
|
||||||
|
childDisplayName, _ := ptr.ValOK(child.GetDisplayName())
|
||||||
|
|
||||||
|
fullFolderName := parentFolder + "/" + childDisplayName
|
||||||
|
|
||||||
|
messageCount[fullFolderName], _ = ptr.ValOK(child.GetTotalItemCount())
|
||||||
|
|
||||||
|
childFolderCount, _ := ptr.ValOK(child.GetChildFolderCount())
|
||||||
|
|
||||||
|
// recursively check for subfolders
|
||||||
|
if childFolderCount > 0 {
|
||||||
|
parentFolder := fullFolderName
|
||||||
|
|
||||||
|
getAllSubFolder(client, testUser, child, parentFolder, messageCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAllSubFolder will recursively traverse inside the restore folder and
|
||||||
|
// verify that data matched in all subfolders
|
||||||
|
func checkAllSubFolder(
|
||||||
|
client *msgraphsdk.GraphServiceClient,
|
||||||
|
testUser string,
|
||||||
|
r models.MailFolderable,
|
||||||
|
parentFolder string,
|
||||||
|
messageCount map[string]int32,
|
||||||
|
) {
|
||||||
|
folderID, ok := ptr.ValOK(r.GetId())
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
fmt.Println("unable to get sub folder ID")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
user := client.UsersById(testUser)
|
||||||
|
folder := user.MailFoldersById(folderID)
|
||||||
|
|
||||||
|
childFolder, err := folder.ChildFolders().Get(context.Background(), nil)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Error getting the drive: %v\n", err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, child := range childFolder.GetValue() {
|
||||||
|
childDisplayName, _ := ptr.ValOK(child.GetDisplayName())
|
||||||
|
|
||||||
|
fullFolderName := parentFolder + "/" + childDisplayName
|
||||||
|
|
||||||
|
childTotalCount, _ := ptr.ValOK(child.GetTotalItemCount())
|
||||||
|
|
||||||
|
if messageCount[fullFolderName] != childTotalCount {
|
||||||
|
fmt.Println("Restore was not succesfull for: ", fullFolderName,
|
||||||
|
"Folder count: ", messageCount[fullFolderName],
|
||||||
|
"Restore count: ", childTotalCount)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
childFolderCount, _ := ptr.ValOK(child.GetChildFolderCount())
|
||||||
|
|
||||||
|
if childFolderCount > 0 {
|
||||||
|
parentFolder := fullFolderName
|
||||||
|
|
||||||
|
checkAllSubFolder(client, testUser, child, parentFolder, messageCount)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user