Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
add sanity tests for chats
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfkeepers committed Jan 26, 2024
1 parent 7cdd943 commit 5a1eee1
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 1 deletion.
36 changes: 36 additions & 0 deletions .github/workflows/sanity-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
push:
branches:
- main
- 5063-chats-backup-v0-integration-tests
workflow_dispatch:
inputs:
user:
Expand Down Expand Up @@ -423,6 +424,41 @@ jobs:

##########################################################################################################################################

# Teams Chats

# generate a folder name
- name: TeamsChats - Create export foldername
id: export-folder-teamschats
run: |
suffix=$(date +"%Y-%m-%d_%H-%M-%S")
echo name="${{ env.RESTORE_DEST_PFX }}$suffix" >> $GITHUB_OUTPUT
- name: TeamsChats - Backup
id: teamschats-backup
timeout-minutes: 30
uses: ./.github/actions/backup-restore-test
with:
service: teamschats
kind: first-backup
backup-args: '--user "${{ vars.CORSO_M365_TEST_USER_ID }}"'
restore-container: '${{ jobs.export-folder-teamschats.outputs.name }}'

Check failure on line 444 in .github/workflows/sanity-test.yaml

View workflow job for this annotation

GitHub Actions / Actions-Lint

undefined variable "jobs". available variables are "env", "github", "inputs", "job", "matrix", "needs", "runner", "secrets", "steps", "strategy", "vars"
log-dir: ${{ env.CORSO_LOG_DIR }}
with-export: true

- name: TeamsChats - Incremental backup
id: teamschats-incremental
timeout-minutes: 30
uses: ./.github/actions/backup-restore-test
with:
service: teamschats
kind: incremental
backup-args: '--group "${{ vars.CORSO_M365_TEST_USER_ID }}"'
restore-container: '${{ jobs.export-folder-teamschats.outputs.name }}'

Check failure on line 456 in .github/workflows/sanity-test.yaml

View workflow job for this annotation

GitHub Actions / Actions-Lint

undefined variable "jobs". available variables are "env", "github", "inputs", "job", "matrix", "needs", "runner", "secrets", "steps", "strategy", "vars"
log-dir: ${{ env.CORSO_LOG_DIR }}
with-export: true

##########################################################################################################################################

# Logging & Notifications

# Upload the original go test output as an artifact for later review.
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*.test
test_results/
testlog/
sanity.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/sanity_test/common/filepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package common

import (
"context"
"fmt"
"io/fs"
"os"
"path/filepath"
Expand All @@ -21,7 +22,7 @@ func BuildFilepathSanitree(
err error,
) error {
if err != nil {
Fatal(ctx, "error passed to filepath walker", err)
Fatal(ctx, fmt.Sprintf("error passed to filepath walker for dir %q", p), err)
}

relPath, err := filepath.Rel(rootDir, p)
Expand Down
93 changes: 93 additions & 0 deletions src/cmd/sanity_test/export/teamschats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package export

import (
"context"
"io/fs"
"strings"

"github.com/microsoftgraph/msgraph-sdk-go/models"

"github.com/alcionai/corso/src/cmd/sanity_test/common"
"github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/pkg/path"
"github.com/alcionai/corso/src/pkg/services/m365/api"
)

func CheckTeamsChatsExport(
ctx context.Context,
ac api.Client,
envs common.Envs,
) {
sourceTree := populateChatsSanitree(
ctx,
ac,
envs.UserID)

fpTree := common.BuildFilepathSanitree(ctx, envs.RestoreContainer)

comparator := func(
ctx context.Context,
expect *common.Sanitree[models.Chatable, models.Chatable],
result *common.Sanitree[fs.FileInfo, fs.FileInfo],
) {
for key := range expect.Leaves {
expect.Leaves[key].Size = 0 // chat 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(
ctx,
sourceTree,
fpTree.Children[path.ChatsCategory.HumanString()],
comparator)

common.Infof(ctx, "Success")
}

func populateChatsSanitree(
ctx context.Context,
ac api.Client,
userID string,
) *common.Sanitree[models.Chatable, models.Chatable] {
root := &common.Sanitree[models.Chatable, models.Chatable]{
ID: userID,
Name: path.ChatsCategory.HumanString(),
Leaves: map[string]*common.Sanileaf[models.Chatable, models.Chatable]{},
// teamschat should not have child containers
}

cc := api.CallConfig{
Expand: []string{"lastMessagePreview"},
}

chats, err := ac.Chats().GetChats(ctx, userID, cc)
if err != nil {
common.Fatal(ctx, "getting channels", err)
}

for _, chat := range chats {
leaf := &common.Sanileaf[
models.Chatable, models.Chatable,
]{
Parent: root,
ID: ptr.Val(chat.GetId()),
Name: ptr.Val(chat.GetId()),
}

root.Leaves[ptr.Val(chat.GetId())] = leaf
}

root.CountLeaves = len(root.Leaves)

return root
}
24 changes: 24 additions & 0 deletions src/cmd/sanity_test/sanity_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func main() {
expCMD.AddCommand(exportSharePointCMD())
expCMD.AddCommand(exportExchangeCMD())
expCMD.AddCommand(exportGroupsCMD())
expCMD.AddCommand(exportTeamsChatsCMD())
root.AddCommand(expCMD)

if err := root.Execute(); err != nil {
Expand Down Expand Up @@ -200,6 +201,29 @@ func sanityTestExportExchange(cmd *cobra.Command, args []string) error {
return nil
}

func exportTeamsChatsCMD() *cobra.Command {
return &cobra.Command{
Use: "teamschats",
Short: "run the teamschats export sanity tests",
DisableAutoGenTag: true,
RunE: sanityTestExportTeamsChats,
}
}

func sanityTestExportTeamsChats(cmd *cobra.Command, args []string) error {
ctx := common.SetDebug(cmd.Context())
envs := common.EnvVars(ctx)

ac, err := common.GetAC()
if err != nil {
return print.Only(ctx, err)
}

export.CheckTeamsChatsExport(ctx, ac, envs)

return nil
}

// ---------------------------------------------------------------------------
// service commands - restore
// ---------------------------------------------------------------------------
Expand Down

0 comments on commit 5a1eee1

Please sign in to comment.