generates test lists for sanity test (#5035)

generates test lists for CI sanity tests

#### 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)
#4754 

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [x] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
This commit is contained in:
Hitesh Pattanayak 2024-01-23 18:16:59 +05:30 committed by GitHub
parent 07da7f16a1
commit 8ca1a05400
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 159 additions and 27 deletions

View File

@ -18,6 +18,7 @@ import (
"github.com/alcionai/corso/src/internal/m365"
exchMock "github.com/alcionai/corso/src/internal/m365/service/exchange/mock"
odStub "github.com/alcionai/corso/src/internal/m365/service/onedrive/stub"
siteMock "github.com/alcionai/corso/src/internal/m365/service/sharepoint/mock"
m365Stub "github.com/alcionai/corso/src/internal/m365/stub"
"github.com/alcionai/corso/src/internal/operations/inject"
"github.com/alcionai/corso/src/internal/tester"
@ -58,7 +59,7 @@ func generateAndRestoreItems(
service path.ServiceType,
cat path.CategoryType,
sel selectors.Selector,
tenantID, userID, destFldr string,
tenantID, resourceID, destFldr string,
howMany int,
dbf dataBuilderFunc,
opts control.Options,
@ -73,7 +74,7 @@ func generateAndRestoreItems(
nowLegacy = dttm.FormatToLegacy(time.Now())
id = uuid.NewString()
subject = "automated " + now[:16] + " - " + id[:8]
body = "automated " + cat.HumanString() + " generation for " + userID + " at " + now + " - " + id
body = "automated " + cat.HumanString() + " generation for " + resourceID + " at " + now + " - " + id
)
items = append(items, item{
@ -94,7 +95,7 @@ func generateAndRestoreItems(
dataColls, err := buildCollections(
service,
tenantID, userID,
tenantID, resourceID,
restoreCfg,
collections)
if err != nil {
@ -192,29 +193,31 @@ type collection struct {
func buildCollections(
service path.ServiceType,
tenant, user string,
tenant, resource string,
restoreCfg control.RestoreConfig,
colls []collection,
) ([]data.RestoreCollection, error) {
collections := make([]data.RestoreCollection, 0, len(colls))
var (
collections = make([]data.RestoreCollection, 0, len(colls))
mc data.Collection
)
for _, c := range colls {
pth, err := path.Build(
tenant,
user,
service,
c.category,
false,
c.PathElements...)
if err != nil {
return nil, err
}
switch {
case service == path.ExchangeService:
emc, err := generateExchangeMockColls(tenant, resource, c)
if err != nil {
return nil, err
}
mc := exchMock.NewCollection(pth, pth, len(c.items))
mc = emc
case service == path.SharePointService:
smc, err := generateSharepointListsMockColls(tenant, resource, c)
if err != nil {
return nil, err
}
for i := 0; i < len(c.items); i++ {
mc.Names[i] = c.items[i].name
mc.Data[i] = c.items[i].data
mc = smc
}
collections = append(collections, data.NoFetchRestoreCollection{Collection: mc})
@ -223,6 +226,49 @@ func buildCollections(
return collections, nil
}
func generateExchangeMockColls(tenant string, resource string, c collection) (*exchMock.DataCollection, error) {
pth, err := path.Build(
tenant,
resource,
path.ExchangeService,
c.category,
false,
c.PathElements...)
if err != nil {
return nil, err
}
emc := exchMock.NewCollection(pth, pth, len(c.items))
for i := 0; i < len(c.items); i++ {
emc.Names[i] = c.items[i].name
emc.Data[i] = c.items[i].data
}
return emc, nil
}
func generateSharepointListsMockColls(tenant string, resource string, c collection) (*siteMock.ListCollection, error) {
pth, err := path.BuildOrPrefix(
tenant,
resource,
path.SharePointService,
c.category,
false)
if err != nil {
return nil, err
}
smc := siteMock.NewCollection(pth, pth, len(c.items))
for i := 0; i < len(c.items); i++ {
smc.Names[i] = c.items[i].name
smc.Data[i] = c.items[i].data
}
return smc, nil
}
var (
folderAName = "folder-a"
folderBName = "b"

View File

@ -7,6 +7,8 @@ import (
. "github.com/alcionai/corso/src/cli/print"
"github.com/alcionai/corso/src/cli/utils"
siteMock "github.com/alcionai/corso/src/internal/m365/service/sharepoint/mock"
"github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/count"
"github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/logger"
@ -14,14 +16,23 @@ import (
"github.com/alcionai/corso/src/pkg/selectors"
)
var spFilesCmd = &cobra.Command{
Use: "files",
Short: "Generate SharePoint files",
RunE: handleSharePointLibraryFileFactory,
}
var (
spFilesCmd = &cobra.Command{
Use: "files",
Short: "Generate SharePoint files",
RunE: handleSharePointLibraryFileFactory,
}
spListsCmd = &cobra.Command{
Use: "lists",
Short: "Generate SharePoint lists",
RunE: handleSharepointListsFactory,
}
)
func AddSharePointCommands(cmd *cobra.Command) {
cmd.AddCommand(spFilesCmd)
cmd.AddCommand(spListsCmd)
}
func handleSharePointLibraryFileFactory(cmd *cobra.Command, args []string) error {
@ -70,3 +81,52 @@ func handleSharePointLibraryFileFactory(cmd *cobra.Command, args []string) error
return nil
}
func handleSharepointListsFactory(cmd *cobra.Command, args []string) error {
var (
ctx = cmd.Context()
service = path.SharePointService
category = path.ListsCategory
errs = fault.New(false)
)
if utils.HasNoFlagsAndShownHelp(cmd) {
return nil
}
ctrl, _, ins, err := getControllerAndVerifyResourceOwner(ctx, Site, path.SharePointService)
if err != nil {
return Only(ctx, err)
}
deets, err := generateAndRestoreItems(
ctx,
ctrl,
service,
category,
selectors.NewSharePointRestore([]string{ins.ID()}).Selector,
Tenant, ins.ID(), Destination,
Count,
func(id, now, subject, body string) []byte {
listBytes, err := siteMock.ListBytes(id)
if err != nil {
logger.CtxErr(ctx, err)
return nil
}
return listBytes
},
control.DefaultOptions(),
errs,
count.New())
if err != nil {
return Only(ctx, err)
}
for _, e := range errs.Recovered() {
logger.CtxErr(ctx, err).Error(e.Error())
}
deets.PrintEntries(ctx)
return nil
}

View File

@ -7,6 +7,7 @@ import (
"testing"
"github.com/alcionai/clues"
"github.com/google/uuid"
kjson "github.com/microsoft/kiota-serialization-json-go"
"github.com/microsoftgraph/msgraph-sdk-go/models"
"github.com/stretchr/testify/require"
@ -23,7 +24,7 @@ var (
type ListCollection struct {
fullPath path.Path
Data []*ListData
Data [][]byte
Names []string
}
@ -56,14 +57,39 @@ func (mlc *ListCollection) Items(
go func() {
defer close(res)
for _, stream := range mlc.Data {
res <- stream
for i, stream := range mlc.Data {
res <- &ListData{
ItemID: mlc.Names[i],
Reader: io.NopCloser(bytes.NewReader(stream)),
}
}
}()
return res
}
func NewCollection(
storagePath path.Path,
locationPath path.Path,
numMessagesToReturn int,
) *ListCollection {
c := &ListCollection{
fullPath: storagePath,
Data: [][]byte{},
Names: []string{},
}
for i := 0; i < numMessagesToReturn; i++ {
// We can plug in whatever data we want here (can be an io.Reader to a test data file if needed)
name := uuid.NewString()
lb, _ := ListBytes("MockListing" + name)
c.Data = append(c.Data, lb)
c.Names = append(c.Names, name)
}
return c
}
type ListData struct {
ItemID string
Reader io.ReadCloser