This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7cdd943
commit 5a1eee1
Showing
5 changed files
with
156 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters