@@ -50,10 +50,16 @@ func (m *mockS3Client) GetObject(ctx context.Context, params *s3.GetObjectInput,
50
50
51
51
func (m * mockS3Client ) UploadPart (ctx context.Context , params * s3.UploadPartInput , optFns ... func (* s3.Options )) (* s3.UploadPartOutput , error ) { //nolint:revive
52
52
buffer := bytes.Buffer {}
53
- _ , err := buffer .ReadFrom (params .Body )
53
+ bufLen , err := buffer .ReadFrom (params .Body )
54
54
if err != nil {
55
55
m .t .Errorf ("error uploading part: %d" , params .PartNumber )
56
56
}
57
+ if * params .ContentLength != bufLen {
58
+ m .t .Errorf ("ContentLength doesn't match buffer length: got %d, expected %d" , * params .ContentLength , bufLen )
59
+ }
60
+ if * params .ContentLength == 0 {
61
+ m .t .Errorf ("ContentLength must be > 0: got %d" , * params .ContentLength )
62
+ }
57
63
m .body = append (m .body , buffer .Bytes ()... )
58
64
e := strconv .Itoa (int (m .partNumber ))
59
65
return & s3.UploadPartOutput {ETag : & e }, nil
@@ -104,19 +110,20 @@ func TestS3Stream_WriteTo(t *testing.T) {
104
110
}
105
111
106
112
func TestS3Stream_ReadFrom (t * testing.T ) {
107
- want := "test body of multi-part upload"
113
+ want := "test body of multi-part upload 40 bytes "
108
114
const DefaultBufferSize = 10
109
115
c := & server.Config {
110
116
S3_BUCKET_NAME : "test-bucket" ,
111
117
}
112
118
filePath := "test"
113
119
s := & s3Stream {
114
- config : c ,
115
- bucket : c .S3_BUCKET_NAME ,
116
- key : filePath ,
117
- size : c .LOGS_BUFFER_SIZE ,
118
- buffer : bytes.Buffer {},
119
- partNumber : 1 ,
120
+ config : c ,
121
+ bucket : c .S3_BUCKET_NAME ,
122
+ key : filePath ,
123
+ size : c .LOGS_BUFFER_SIZE ,
124
+ multiPartSize : 20 ,
125
+ buffer : bytes.Buffer {},
126
+ partNumber : 1 ,
120
127
client : & mockS3Client {
121
128
t : t ,
122
129
bucket : c .S3_BUCKET_NAME ,
0 commit comments