From a2439264b2f9346c6a1e481a5f07a997f83e4988 Mon Sep 17 00:00:00 2001 From: jonaustin09 Date: Thu, 24 Aug 2023 18:37:01 +0400 Subject: [PATCH] fix: Fixes #195, fixed DeleteObjects action response structure --- backend/posix/posix.go | 2 +- integration/action-tests.go | 3 +- integration/tests.go | 61 ++++++++++++++++++------------------- s3response/s3response.go | 2 +- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/backend/posix/posix.go b/backend/posix/posix.go index 79abec9..87f47e2 100644 --- a/backend/posix/posix.go +++ b/backend/posix/posix.go @@ -1058,7 +1058,7 @@ func (p *Posix) DeleteObjects(ctx context.Context, input *s3.DeleteObjectsInput) return s3response.DeleteObjectsResult{ Deleted: delResult, - Errors: errs, + Error: errs, }, nil } diff --git a/integration/action-tests.go b/integration/action-tests.go index 0cb7699..10c5cdb 100644 --- a/integration/action-tests.go +++ b/integration/action-tests.go @@ -52,8 +52,7 @@ func TestDeleteObject(s *S3Conf) { func TestDeleteObjects(s *S3Conf) { DeleteObjects_empty_input(s) - //TODO: Uncomment this after fixing the bug: #195 - // DeleteObjects_non_existing_objects(s) + DeleteObjects_non_existing_objects(s) DeleteObjects_success(s) } diff --git a/integration/tests.go b/integration/tests.go index 5bb23f9..6edc0c4 100644 --- a/integration/tests.go +++ b/integration/tests.go @@ -713,40 +713,39 @@ func DeleteObjects_empty_input(s *S3Conf) { }) } -//TODO: Uncomment the test after fixing the bug: #195 -// func DeleteObjects_non_existing_objects(s *S3Conf) { -// testName := "DeleteObjects_empty_input" -// actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { -// delObjects := []types.ObjectIdentifier{{Key: getPtr("obj1")}, {Key: getPtr("obj2")}} -// -// ctx, cancel := context.WithTimeout(context.Background(), shortTimeout) -// out, err := s3client.DeleteObjects(ctx, &s3.DeleteObjectsInput{ -// Bucket: &bucket, -// Delete: &types.Delete{ -// Objects: delObjects, -// }, -// }) -// cancel() -// if err != nil { -// return err -// } +func DeleteObjects_non_existing_objects(s *S3Conf) { + testName := "DeleteObjects_empty_input" + actionHandler(s, testName, func(s3client *s3.Client, bucket string) error { + delObjects := []types.ObjectIdentifier{{Key: getPtr("obj1")}, {Key: getPtr("obj2")}} -// if len(out.Deleted) != 0 { -// return fmt.Errorf("expected deleted object count 0, instead got %v", len(out.Deleted)) -// } -// if len(out.Errors) != 2 { -// return fmt.Errorf("expected 2 errors, instead got %v", len(out.Errors)) -// } + ctx, cancel := context.WithTimeout(context.Background(), shortTimeout) + out, err := s3client.DeleteObjects(ctx, &s3.DeleteObjectsInput{ + Bucket: &bucket, + Delete: &types.Delete{ + Objects: delObjects, + }, + }) + cancel() + if err != nil { + return err + } -// for _, delErr := range out.Errors { -// if *delErr.Code != "NoSuchKey" { -// return fmt.Errorf("expected NoSuchKey error, instead got %v", *delErr.Code) -// } -// } + if len(out.Deleted) != 0 { + return fmt.Errorf("expected deleted object count 0, instead got %v", len(out.Deleted)) + } + if len(out.Errors) != 2 { + return fmt.Errorf("expected 2 errors, instead got %v", len(out.Errors)) + } -// return nil -// }) -// } + for _, delErr := range out.Errors { + if *delErr.Code != "NoSuchKey" { + return fmt.Errorf("expected NoSuchKey error, instead got %v", *delErr.Code) + } + } + + return nil + }) +} func DeleteObjects_success(s *S3Conf) { testName := "DeleteObjects_success" diff --git a/s3response/s3response.go b/s3response/s3response.go index f7cc739..66743f2 100644 --- a/s3response/s3response.go +++ b/s3response/s3response.go @@ -116,7 +116,7 @@ type DeleteObjects struct { type DeleteObjectsResult struct { Deleted []types.DeletedObject - Errors []types.Error + Error []types.Error } type SelectObjectContentPayload struct { Expression *string