Fix sanity tests for SharePoint and Groups (#4740)

<!-- 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
- [ ]  Unit test
- [ ] 💚 E2E
This commit is contained in:
Abin Simon 2023-11-29 13:26:09 +05:30 committed by GitHub
parent 1ae9c05651
commit 925c70d9d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 51 additions and 11 deletions

View File

@ -391,7 +391,7 @@ jobs:
log-dir: ${{ env.CORSO_LOG_DIR }}
with-export: true
# generate some more enteries for incremental check
# generate some more entries for incremental check
- name: Groups - Create new data (for incremental)
timeout-minutes: 30
working-directory: ./src/cmd/factory

View File

@ -3,6 +3,8 @@ package export
import (
"context"
"io/fs"
"path/filepath"
"strings"
"github.com/microsoftgraph/msgraph-sdk-go/models"
@ -21,21 +23,31 @@ func CheckGroupsExport(
// assumes we only need to sanity check the default site.
// should we expand this to check all sites in the group?
// are we backing up / restoring more than the default site?
site, err := ac.Sites().GetByID(ctx, envs.TeamSiteID, api.CallConfig{})
if err != nil {
common.Fatal(ctx, "getting the drive:", err)
}
drive, err := ac.Sites().GetDefaultDrive(ctx, envs.TeamSiteID)
if err != nil {
common.Fatal(ctx, "getting the drive:", err)
}
checkChannelMessagesExport(
ctx,
ac,
envs)
envs.RestoreContainer = filepath.Join(
envs.RestoreContainer,
"Libraries",
ptr.Val(site.GetName()),
"Documents") // check in default loc
driveish.CheckExport(
ctx,
ac,
drive,
envs)
checkChannelMessagesExport(
ctx,
ac,
envs)
}
func checkChannelMessagesExport(
@ -55,7 +67,19 @@ func checkChannelMessagesExport(
expect *common.Sanitree[models.Channelable, models.ChatMessageable],
result *common.Sanitree[fs.FileInfo, fs.FileInfo],
) {
common.CompareLeaves(ctx, expect.Leaves, result.Leaves, nil)
for key := range expect.Leaves {
expect.Leaves[key].Size = 0 // msg sizes cannot be compared
}
updatedResultLeaves := map[string]*common.Sanileaf[fs.FileInfo, fs.FileInfo]{}
for key, leaf := range result.Leaves {
key = strings.TrimSuffix(key, ".json")
leaf.Size = 0 // we cannot compare sizes
updatedResultLeaves[key] = leaf
}
common.CompareLeaves(ctx, expect.Leaves, updatedResultLeaves, nil)
}
common.CompareDiffTrees(
@ -107,7 +131,21 @@ func populateMessagesSanitree(
common.Fatal(ctx, "getting channel messages", err)
}
filteredMsgs := []models.ChatMessageable{}
for _, msg := range msgs {
// filter out system messages (we don't really work with them)
if api.IsNotSystemMessage(msg) {
filteredMsgs = append(filteredMsgs, msg)
}
}
if len(filteredMsgs) == 0 {
common.Infof(ctx, "skipped empty channel: %s", ptr.Val(ch.GetDisplayName()))
continue
}
for _, msg := range filteredMsgs {
child.Leaves[ptr.Val(msg.GetId())] = &common.Sanileaf[
models.Channelable,
models.ChatMessageable,

View File

@ -2,6 +2,7 @@ package export
import (
"context"
"path/filepath"
"github.com/alcionai/corso/src/cmd/sanity_test/common"
"github.com/alcionai/corso/src/cmd/sanity_test/driveish"
@ -18,6 +19,7 @@ func CheckSharePointExport(
common.Fatal(ctx, "getting the drive:", err)
}
envs.RestoreContainer = filepath.Join(envs.RestoreContainer, "Libraries/Documents") // check in default loc
driveish.CheckExport(
ctx,
ac,

View File

@ -165,7 +165,7 @@ func (c Channels) NewChannelMessageDeltaPager(
// unknownFutureValue.
const channelMessageSystemMessageContent = "<systemEventMessage/>"
func filterOutSystemMessages(cm models.ChatMessageable) bool {
func IsNotSystemMessage(cm models.ChatMessageable) bool {
if ptr.Val(cm.GetMessageType()) == models.SYSTEMEVENTMESSAGE_CHATMESSAGETYPE {
return false
}
@ -195,7 +195,7 @@ func (c Channels) GetChannelMessageIDs(
cc.CanMakeDeltaQueries,
0,
pagers.AddedAndRemovedByDeletedDateTime[models.ChatMessageable],
filterOutSystemMessages)
IsNotSystemMessage)
return aar, clues.Stack(err).OrNil()
}

View File

@ -152,7 +152,7 @@ func testEnumerateChannelMessageReplies(
assert.Equal(t, replyIDs, msgReplyIDs)
}
func (suite *ChannelsPagerIntgSuite) TestFilterOutSystemMessages() {
func (suite *ChannelsPagerIntgSuite) TestIsSystemMessage() {
systemMessage := models.NewChatMessage()
systemMessage.SetMessageType(ptr.To(models.SYSTEMEVENTMESSAGE_CHATMESSAGETYPE))
@ -211,7 +211,7 @@ func (suite *ChannelsPagerIntgSuite) TestFilterOutSystemMessages() {
}
for _, test := range table {
suite.Run(test.name, func() {
test.expect(suite.T(), filterOutSystemMessages(test.cm))
test.expect(suite.T(), IsNotSystemMessage(test.cm))
})
}
}