Repository: pingcap/tidb
File: pkg/objstore/s3store/client_test.go (Go)

Code before:
				}

				s.MockS3.EXPECT().PutObject(gomock.Any(), gomock.Any(), gomock.Any()).
					DoAndReturn(func(_ context.Context, input *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error) {
						require.Equal(t, "bucket", aws.ToString(input.Bucket))
						require.True(t, strings.HasPrefix(aws.ToString(input.Key), "prefix/perm-check/"))
						assertContentMD5Option(t, optFns, tc.s3Compatible)
						return &s3.PutObjectOutput{}, nil
					})
				s.MockS3.EXPECT().DeleteObject(gomock.Any(), gomock.Any(), gomock.Any()).
					DoAndReturn(func(_ context.Context, input *s3.DeleteObjectInput, _ ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) {
						require.Equal(t, "bucket", aws.ToString(input.Bucket))
						require.True(t, strings.HasPrefix(aws.ToString(input.Key), "prefix/perm-check/"))
						return &s3.DeleteObjectOutput{}, nil
					})

				require.NoError(t, cli.CheckPutAndDeleteObject(ctx))
				require.True(t, s.Controller.Satisfied())
			})
		}
	})

	t.Run("MultipartWriterUploadPart", func(t *testing.T) {
		for _, tc := range []struct {
			name         string
			s3Compatible bool
		}{
			{name: "official_s3", s3Compatible: false},
			{name: "ks3", s3Compatible: true},
		} {
			t.Run(tc.name, func(t *testing.T) {
				s := CreateS3Suite(t)
				cli := &s3Client{
					svc:          s.MockS3,
					BucketPrefix: storeapi.NewBucketPrefix("bucket", "prefix/"),
					options:      &backuppb.S3{Bucket: "bucket"},
					isKS3:        tc.s3Compatible,
				}

				s.MockS3.EXPECT().CreateMultipartUpload(gomock.Any(), gomock.Any(), gomock.Any()).
					DoAndReturn(func(_ context.Context, input *s3.CreateMultipartUploadInput, _ ...func(*s3.Options)) (*s3.CreateMultipartUploadOutput, error) {
						require.Equal(t, "bucket", aws.ToString(input.Bucket))
						require.Equal(t, "prefix/object", aws.ToString(input.Key))
						return &s3.CreateMultipartUploadOutput{
							Bucket:   input.Bucket,
							Key:      input.Key,
							UploadId: aws.String("upload-id"),
						}, nil
					})
				s.MockS3.EXPECT().UploadPart(gomock.Any(), gomock.Any(), gomock.Any()).
					DoAndReturn(func(_ context.Context, input *s3.UploadPartInput, optFns ...func(*s3.Options)) (*s3.UploadPartOutput, error) {

Review comment (suggestion):
The test case variable name `s3Compatible` is misleading. It should be renamed to something like `isKS3` to match the semantic change of this PR and the field it's assigned to.

Code after:
				}

				s.MockS3.EXPECT().PutObject(gomock.Any(), gomock.Any(), gomock.Any()).
					DoAndReturn(func(_ context.Context, input *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error) {
						require.Equal(t, "bucket", aws.ToString(input.Bucket))
						require.True(t, strings.HasPrefix(aws.ToString(input.Key), "prefix/perm-check/"))
						assertContentMD5Option(t, optFns, tc.s3Compatible)
						return &s3.PutObjectOutput{}, nil
					})
				s.MockS3.EXPECT().DeleteObject(gomock.Any(), gomock.Any(), gomock.Any()).
					DoAndReturn(func(_ context.Context, input *s3.DeleteObjectInput, _ ...func(*s3.Options)) (*s3.DeleteObjectOutput, error) {
						require.Equal(t, "bucket", aws.ToString(input.Bucket))
						require.True(t, strings.HasPrefix(aws.ToString(input.Key), "prefix/perm-check/"))
						return &s3.DeleteObjectOutput{}, nil
					})

				require.NoError(t, cli.CheckPutAndDeleteObject(ctx))
				require.True(t, s.Controller.Satisfied())
			})
		}
	})

	t.Run("MultipartWriterUploadPart", func(t *testing.T) {
		for _, tc := range []struct {
			name         string
			s3Compatible bool
		}{
			{name: "official_s3", s3Compatible: false},
			{name: "s3_compatible", s3Compatible: true},
		} {
			t.Run(tc.name, func(t *testing.T) {
				s := CreateS3Suite(t)
				cli := &s3Client{
					svc:          s.MockS3,
					BucketPrefix: storeapi.NewBucketPrefix("bucket", "prefix/"),
					options:      &backuppb.S3{Bucket: "bucket"},
					s3Compatible: tc.s3Compatible,
				}

				s.MockS3.EXPECT().CreateMultipartUpload(gomock.Any(), gomock.Any(), gomock.Any()).
					DoAndReturn(func(_ context.Context, input *s3.CreateMultipartUploadInput, _ ...func(*s3.Options)) (*s3.CreateMultipartUploadOutput, error) {
						require.Equal(t, "bucket", aws.ToString(input.Bucket))
						require.Equal(t, "prefix/object", aws.ToString(input.Key))
						return &s3.CreateMultipartUploadOutput{
							Bucket:   input.Bucket,
							Key:      input.Key,
							UploadId: aws.String("upload-id"),
						}, nil
					})
				s.MockS3.EXPECT().UploadPart(gomock.Any(), gomock.Any(), gomock.Any()).
					DoAndReturn(func(_ context.Context, input *s3.UploadPartInput, optFns ...func(*s3.Options)) (*s3.UploadPartOutput, error) {