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

Code before:
							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) {
						require.Equal(t, "bucket", aws.ToString(input.Bucket))
						require.Equal(t, "prefix/object", aws.ToString(input.Key))
						assertContentMD5Option(t, optFns, tc.s3Compatible)
						return &s3.UploadPartOutput{ETag: aws.String("etag")}, nil
					})

				w, err := cli.MultipartWriter(ctx, "object")
				require.NoError(t, err)
				_, err = w.Write(ctx, []byte("part"))
				require.NoError(t, err)
				require.True(t, s.Controller.Satisfied())
			})
		}
	})

	t.Run("MultipartUploaderClientOptions", 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/"),
					isKS3:        tc.s3Compatible,
				}

				up := cli.MultipartUploader("object", 5*1024*1024, 2)
				mp, ok := up.(*multipartUploader)
				require.True(t, ok)

				assertContentMD5Option(t, mp.uploader.ClientOptions, tc.s3Compatible)
				require.True(t, s.Controller.Satisfied())
			})
		}
	})
}

func TestClientCopyObject(t *testing.T) {
	s := CreateS3Suite(t)

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:
							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) {
						require.Equal(t, "bucket", aws.ToString(input.Bucket))
						require.Equal(t, "prefix/object", aws.ToString(input.Key))
						assertContentMD5Option(t, optFns, tc.s3Compatible)
						return &s3.UploadPartOutput{ETag: aws.String("etag")}, nil
					})

				w, err := cli.MultipartWriter(ctx, "object")
				require.NoError(t, err)
				_, err = w.Write(ctx, []byte("part"))
				require.NoError(t, err)
				require.True(t, s.Controller.Satisfied())
			})
		}
	})

	t.Run("MultipartUploaderClientOptions", 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/"),
					s3Compatible: tc.s3Compatible,
				}

				up := cli.MultipartUploader("object", 5*1024*1024, 2)
				mp, ok := up.(*multipartUploader)
				require.True(t, ok)

				assertContentMD5Option(t, mp.uploader.ClientOptions, tc.s3Compatible)
				if tc.s3Compatible {
					require.Equal(t, aws.RequestChecksumCalculationWhenRequired, mp.uploader.RequestChecksumCalculation)
				}
				require.True(t, s.Controller.Satisfied())
			})
		}
	})
}