diff --git a/src/cmd/sanity_test/driveish/driveish.go b/src/cmd/sanity_test/driveish/driveish.go index 63d16a3c5..12f431790 100644 --- a/src/cmd/sanity_test/driveish/driveish.go +++ b/src/cmd/sanity_test/driveish/driveish.go @@ -3,6 +3,7 @@ package driveish import ( "context" + "github.com/alcionai/clues" "github.com/microsoftgraph/msgraph-sdk-go/models" "github.com/alcionai/corso/src/cmd/sanity_test/common" @@ -15,10 +16,23 @@ const ( owner = "owner" ) +// sanitree population will grab a superset of data in the drive. +// this increases the chance that we'll run into a race collision with +// the cleanup script. Sometimes that's okay (deleting old data that +// isn't scrutinized in the test), other times it's not. We mark whether +// that's okay to do or not by specifying the folder that's being +// scrutinized for the test. Any errors within that folder should cause +// a fatal exit. Errors outside of that folder get ignored. +// +// since we're using folder names, requireNoErrorsWithinFolderName will +// work best (ie: have the fewest collisions/side-effects) if the folder +// name is very specific. Standard sanity tests should include timestamps, +// which should help ensure that. Be warned if you try to use it with +// a more generic name: unintended effects could occur. func populateSanitree( ctx context.Context, ac api.Client, - driveID string, + driveID, requireNoErrorsWithinFolderName string, ) *common.Sanitree[models.DriveItemable, models.DriveItemable] { common.Infof(ctx, "building sanitree for drive: %s", driveID) @@ -27,10 +41,12 @@ func populateSanitree( common.Fatal(ctx, "getting drive root folder", err) } + rootName := ptr.Val(root.GetName()) + stree := &common.Sanitree[models.DriveItemable, models.DriveItemable]{ Self: root, ID: ptr.Val(root.GetId()), - Name: ptr.Val(root.GetName()), + Name: rootName, Leaves: map[string]*common.Sanileaf[models.DriveItemable, models.DriveItemable]{}, Children: map[string]*common.Sanitree[models.DriveItemable, models.DriveItemable]{}, } @@ -40,6 +56,8 @@ func populateSanitree( ac, driveID, stree.Name+"/", + requireNoErrorsWithinFolderName, + rootName == requireNoErrorsWithinFolderName, stree) return stree @@ -48,14 +66,27 @@ func populateSanitree( func recursivelyBuildTree( ctx context.Context, ac api.Client, - driveID, location string, + driveID, location, requireNoErrorsWithinFolderName string, + isChildOfFolderRequiringNoErrors bool, stree *common.Sanitree[models.DriveItemable, models.DriveItemable], ) { common.Debugf(ctx, "adding: %s", location) children, err := ac.Drives().GetFolderChildren(ctx, driveID, stree.ID) if err != nil { - common.Fatal(ctx, "getting drive children by id", err) + if isChildOfFolderRequiringNoErrors { + common.Fatal(ctx, "getting drive children by id", err) + } + + common.Infof( + ctx, + "ignoring error getting children in directory %q because it is not within directory %q\nerror: %s\n%+v", + location, + requireNoErrorsWithinFolderName, + err.Error(), + clues.ToCore(err)) + + return } for _, driveItem := range children { @@ -72,13 +103,15 @@ func recursivelyBuildTree( continue } + cannotAllowErrors := isChildOfFolderRequiringNoErrors || itemName == requireNoErrorsWithinFolderName + branch := &common.Sanitree[models.DriveItemable, models.DriveItemable]{ Parent: stree, Self: driveItem, ID: itemID, Name: itemName, Expand: map[string]any{ - expandPermissions: permissionIn(ctx, ac, driveID, itemID), + expandPermissions: permissionIn(ctx, ac, driveID, itemID, cannotAllowErrors), }, Leaves: map[string]*common.Sanileaf[models.DriveItemable, models.DriveItemable]{}, Children: map[string]*common.Sanitree[models.DriveItemable, models.DriveItemable]{}, @@ -91,6 +124,8 @@ func recursivelyBuildTree( ac, driveID, location+branch.Name+"/", + requireNoErrorsWithinFolderName, + cannotAllowErrors, branch) } diff --git a/src/cmd/sanity_test/driveish/export.go b/src/cmd/sanity_test/driveish/export.go index c07cb173f..80d608e61 100644 --- a/src/cmd/sanity_test/driveish/export.go +++ b/src/cmd/sanity_test/driveish/export.go @@ -31,7 +31,8 @@ func CheckExport( root := populateSanitree( ctx, ac, - driveID) + driveID, + envs.RestoreContainer) sourceTree, ok := root.Children[envs.SourceContainer] common.Assert( diff --git a/src/cmd/sanity_test/driveish/restore.go b/src/cmd/sanity_test/driveish/restore.go index 2d861eeb9..a95c77cef 100644 --- a/src/cmd/sanity_test/driveish/restore.go +++ b/src/cmd/sanity_test/driveish/restore.go @@ -45,7 +45,7 @@ func CheckRestoration( "drive_id", driveID, "drive_name", driveName) - root := populateSanitree(ctx, ac, driveID) + root := populateSanitree(ctx, ac, driveID, envs.RestoreContainer) sourceTree, ok := root.Children[envs.SourceContainer] common.Assert( @@ -85,12 +85,24 @@ func permissionIn( ctx context.Context, ac api.Client, driveID, itemID string, + cannotAllowErrors bool, ) []common.PermissionInfo { pi := []common.PermissionInfo{} pcr, err := ac.Drives().GetItemPermission(ctx, driveID, itemID) if err != nil { - common.Fatal(ctx, "getting permission", err) + if cannotAllowErrors { + common.Fatal(ctx, "getting permission", err) + } + + common.Infof( + ctx, + "ignoring error getting permissions for %q\nerror: %s,%+v", + itemID, + err.Error(), + clues.ToCore(err)) + + return []common.PermissionInfo{} } for _, perm := range pcr.GetValue() {