From 75c5cb3582d7d3059e6569de07e37ce6a4c99fd6 Mon Sep 17 00:00:00 2001 From: neha_gupta Date: Wed, 13 Sep 2023 00:00:55 +0530 Subject: [PATCH] fix sanity test for groups (#4226) Handle- - empty channel - do to add item if deleted #### Does this PR need a docs update or release note? - [ ] :no_entry: No #### Type of change - [ ] :bug: Bugfix #### Issue(s) * # #### Test Plan - [ ] :muscle: Manual - [ ] :zap: Unit test --- .github/workflows/sanity-test.yaml | 67 ++++++++++----------- src/internal/m365/graph/errors.go | 14 +++-- src/internal/m365/graph/errors_test.go | 10 +++ src/pkg/services/m365/api/channels_pager.go | 9 +++ 4 files changed, 60 insertions(+), 40 deletions(-) diff --git a/.github/workflows/sanity-test.yaml b/.github/workflows/sanity-test.yaml index 87c1a4423..1c155a255 100644 --- a/.github/workflows/sanity-test.yaml +++ b/.github/workflows/sanity-test.yaml @@ -328,44 +328,43 @@ jobs: # Groups and Teams - # TODO(ashmrtn): Reenable when delta request issue is resolved. + # generate new entries for test + - name: Groups - Create new data + id: new-data-creation-groups + working-directory: ./src/cmd/factory + run: | + suffix=$(date +"%Y-%m-%d_%H-%M-%S") - ## generate new entries for test - #- name: Groups - Create new data - # id: new-data-creation-groups - # working-directory: ./src/cmd/factory - # run: | - # suffix=$(date +"%Y-%m-%d_%H-%M-%S") + go run . sharepoint files \ + --site ${{ vars.CORSO_M365_TEST_GROUPS_SITE_URL }} \ + --user ${{ env.TEST_USER }} \ + --secondaryuser ${{ env.CORSO_SECONDARY_M365_TEST_USER_ID }} \ + --tenant ${{ secrets.TENANT_ID }} \ + --destination ${{ env.RESTORE_DEST_PFX }}$suffix \ + --count 4 - # go run . sharepoint files \ - # --site ${{ vars.CORSO_M365_TEST_GROUPS_SITE_URL }} \ - # --user ${{ env.TEST_USER }} \ - # --secondaryuser ${{ env.CORSO_SECONDARY_M365_TEST_USER_ID }} \ - # --tenant ${{ secrets.TENANT_ID }} \ - # --destination ${{ env.RESTORE_DEST_PFX }}$suffix \ - # --count 4 + echo result="${suffix}" >> $GITHUB_OUTPUT - # echo result="${suffix}" >> $GITHUB_OUTPUT + - name: Groups - Backup + id: groups-backup + uses: ./.github/actions/backup-restore-test + with: + service: groups + kind: initial + backup-args: '--group "${{ vars.CORSO_M365_TEST_TEAM_ID }}"' + test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-groups.outputs.result }}' + log-dir: ${{ env.CORSO_LOG_DIR }} - #- name: Groups - Backup - # id: groups-backup - # uses: ./.github/actions/backup-restore-test - # with: - # service: groups - # kind: initial - # backup-args: '--group "${{ vars.CORSO_M365_TEST_TEAM_ID }}"' - # test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-groups.outputs.result }}' - # log-dir: ${{ env.CORSO_LOG_DIR }} - - #- name: Teams - Backup - # id: teams-backup - # uses: ./.github/actions/backup-restore-test - # with: - # service: teams - # kind: initial - # backup-args: '--group "${{ vars.CORSO_M365_TEST_TEAM_ID }}"' - # test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-groups.outputs.result }}' - # log-dir: ${{ env.CORSO_LOG_DIR }} +# Since it will be alias, will reenable if required + # - name: Teams - Backup + # id: teams-backup + # uses: ./.github/actions/backup-restore-test + # with: + # service: teams + # kind: initial + # backup-args: '--group "${{ vars.CORSO_M365_TEST_TEAM_ID }}"' + # test-folder: '${{ env.RESTORE_DEST_PFX }}${{ steps.new-data-creation-groups.outputs.result }}' + # log-dir: ${{ env.CORSO_LOG_DIR }} # TODO: incrementals diff --git a/src/internal/m365/graph/errors.go b/src/internal/m365/graph/errors.go index e67198011..327d7edeb 100644 --- a/src/internal/m365/graph/errors.go +++ b/src/internal/m365/graph/errors.go @@ -63,11 +63,12 @@ const ( type errorMessage string const ( - IOErrDuringRead errorMessage = "IO error during request payload read" - MysiteURLNotFound errorMessage = "unable to retrieve user's mysite url" - MysiteNotFound errorMessage = "user's mysite not found" - NoSPLicense errorMessage = "Tenant does not have a SPO license" - usersCannotBeResolved errorMessage = "One or more users could not be resolved" + IOErrDuringRead errorMessage = "IO error during request payload read" + MysiteURLNotFound errorMessage = "unable to retrieve user's mysite url" + MysiteNotFound errorMessage = "user's mysite not found" + NoSPLicense errorMessage = "Tenant does not have a SPO license" + parameterDeltaTokenNotSupported errorMessage = "Parameter 'DeltaToken' not supported for this request" + usersCannotBeResolved errorMessage = "One or more users could not be resolved" ) const ( @@ -134,6 +135,7 @@ func IsErrItemNotFound(err error) bool { func IsErrInvalidDelta(err error) bool { return hasErrorCode(err, syncStateNotFound, resyncRequired, syncStateInvalid) || + hasErrorMessage(err, parameterDeltaTokenNotSupported) || errors.Is(err, ErrInvalidDelta) } @@ -279,7 +281,7 @@ func hasErrorMessage(err error, msgs ...errorMessage) bool { cs[i] = string(c) } - return filters.Equal(cs).Compare(msg) + return filters.Contains(cs).Compare(msg) } // Wrap is a helper function that extracts ODataError metadata from diff --git a/src/internal/m365/graph/errors_test.go b/src/internal/m365/graph/errors_test.go index 8f043074b..e8049a067 100644 --- a/src/internal/m365/graph/errors_test.go +++ b/src/internal/m365/graph/errors_test.go @@ -198,6 +198,11 @@ func (suite *GraphErrorsUnitSuite) TestIsErrInvalidDelta() { err: odErr("fnords"), expect: assert.False, }, + { + name: "non-matching oDataErrMsg", + err: odErrMsg("fnords", "deltatoken not supported"), + expect: assert.False, + }, { name: "resync-required oDataErr", err: odErr(string(resyncRequired)), @@ -208,6 +213,11 @@ func (suite *GraphErrorsUnitSuite) TestIsErrInvalidDelta() { err: odErr(string(syncStateInvalid)), expect: assert.True, }, + { + name: "deltatoken not supported oDataErrMsg", + err: odErrMsg("fnords", string(parameterDeltaTokenNotSupported)), + expect: assert.True, + }, // next two tests are to make sure the checks are case insensitive { name: "resync-required oDataErr camelcase", diff --git a/src/pkg/services/m365/api/channels_pager.go b/src/pkg/services/m365/api/channels_pager.go index 3eb410d2a..a3ef2e9a3 100644 --- a/src/pkg/services/m365/api/channels_pager.go +++ b/src/pkg/services/m365/api/channels_pager.go @@ -119,6 +119,15 @@ func (c Channels) GetChannelMessageIDsDelta( continue } + if graph.IsErrInvalidDelta(err) { + logger.Ctx(ctx).Infow("delta token not supported", "delta_link", prevDelta) + + added = map[string]struct{}{} + deleted = map[string]struct{}{} + + break + } + if err != nil { return nil, nil, DeltaUpdate{}, graph.Wrap(ctx, err, "retrieving page of channel messages") }