Delete Non-current versions (#1735)

- Delete Non-current API
- Delete non current modal implementation
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
This commit is contained in:
Alex
2022-03-18 13:07:34 -07:00
committed by GitHub
parent d7fef8d89e
commit 5ab5232474
11 changed files with 366 additions and 24 deletions

View File

@@ -583,6 +583,7 @@ func Test_deleteObjects(t *testing.T) {
path string
versionID string
recursive bool
nonCurrent bool
listFunc func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent
removeFunc func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult
}
@@ -594,9 +595,10 @@ func Test_deleteObjects(t *testing.T) {
{
test: "Remove single object",
args: args{
path: "obj.txt",
versionID: "",
recursive: false,
path: "obj.txt",
versionID: "",
recursive: false,
nonCurrent: false,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: nil}
@@ -609,9 +611,10 @@ func Test_deleteObjects(t *testing.T) {
{
test: "Error on Remove single object",
args: args{
path: "obj.txt",
versionID: "",
recursive: false,
path: "obj.txt",
versionID: "",
recursive: false,
nonCurrent: false,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
@@ -624,9 +627,10 @@ func Test_deleteObjects(t *testing.T) {
{
test: "Remove multiple objects",
args: args{
path: "path/",
versionID: "",
recursive: true,
path: "path/",
versionID: "",
recursive: true,
nonCurrent: false,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: nil}
@@ -647,9 +651,10 @@ func Test_deleteObjects(t *testing.T) {
// while deleting multiple objects
test: "Error on Remove multiple objects 1",
args: args{
path: "path/",
versionID: "",
recursive: true,
path: "path/",
versionID: "",
recursive: true,
nonCurrent: false,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: nil}
@@ -670,9 +675,58 @@ func Test_deleteObjects(t *testing.T) {
// while deleting multiple objects
test: "Error on Remove multiple objects 2",
args: args{
path: "path/",
versionID: "",
recursive: true,
path: "path/",
versionID: "",
recursive: true,
nonCurrent: false,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
close(resultCh)
return resultCh
},
listFunc: func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent {
ch := make(chan *mc.ClientContent, 1)
ch <- &mc.ClientContent{}
close(ch)
return ch
},
},
wantError: errors.New("probe error"),
},
{
// Description handle error when error happens on remove function
// while deleting multiple objects
test: "Remove non current objects",
args: args{
path: "path/",
versionID: "",
recursive: true,
nonCurrent: true,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: nil}
close(resultCh)
return resultCh
},
listFunc: func(ctx context.Context, opts mc.ListOptions) <-chan *mc.ClientContent {
ch := make(chan *mc.ClientContent, 1)
ch <- &mc.ClientContent{}
close(ch)
return ch
},
},
wantError: nil,
},
{
// Description handle error when error happens on remove function
// while deleting multiple objects
test: "Error deleting non current objects",
args: args{
path: "path/",
versionID: "",
recursive: true,
nonCurrent: true,
removeFunc: func(ctx context.Context, isIncomplete, isRemoveBucket, isBypass bool, contentCh <-chan *mc.ClientContent) <-chan mc.RemoveResult {
resultCh := make(chan mc.RemoveResult, 1)
resultCh <- mc.RemoveResult{Err: probe.NewError(errors.New("probe error"))}
@@ -695,7 +749,7 @@ func Test_deleteObjects(t *testing.T) {
t.Run(tt.test, func(t *testing.T) {
mcListMock = tt.args.listFunc
mcRemoveMock = tt.args.removeFunc
err := deleteObjects(ctx, s3Client1, tt.args.bucket, tt.args.path, tt.args.versionID, tt.args.recursive, false)
err := deleteObjects(ctx, s3Client1, tt.args.bucket, tt.args.path, tt.args.versionID, tt.args.recursive, false, tt.args.nonCurrent)
if err == nil && tt.wantError != nil {
t.Errorf("deleteObjects() error: %v, wantErr: %v", err, tt.wantError)
} else if err != nil && tt.wantError == nil {