2023-03-20 08:13:56 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/xml"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2023-06-21 14:16:40 +00:00
|
|
|
s3Errors "git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/errors"
|
2023-03-20 08:13:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPeriodicWriter(t *testing.T) {
|
|
|
|
const dur = 100 * time.Millisecond
|
|
|
|
const whitespaces = 8
|
|
|
|
expected := []byte(xml.Header)
|
|
|
|
for i := 0; i < whitespaces; i++ {
|
|
|
|
expected = append(expected, []byte(" ")...)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("writes data", func(t *testing.T) {
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
stop := periodicXMLWriter(buf, dur)
|
|
|
|
|
|
|
|
// N number of whitespaces + half durations to guarantee at least N writes in buffer
|
|
|
|
time.Sleep(whitespaces*dur + dur/2)
|
|
|
|
require.True(t, stop())
|
|
|
|
require.Equal(t, expected, buf.Bytes())
|
|
|
|
|
|
|
|
t.Run("no additional data after stop", func(t *testing.T) {
|
|
|
|
time.Sleep(2 * dur)
|
|
|
|
require.Equal(t, expected, buf.Bytes())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("does not write data", func(t *testing.T) {
|
|
|
|
buf := bytes.NewBuffer(nil)
|
|
|
|
stop := periodicXMLWriter(buf, dur)
|
|
|
|
time.Sleep(dur / 2)
|
|
|
|
require.False(t, stop())
|
|
|
|
require.Empty(t, buf.Bytes())
|
|
|
|
|
|
|
|
t.Run("disabled", func(t *testing.T) {
|
|
|
|
stop = periodicXMLWriter(buf, 0)
|
|
|
|
require.False(t, stop())
|
|
|
|
require.Empty(t, buf.Bytes())
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2023-06-21 14:16:40 +00:00
|
|
|
|
|
|
|
func TestMultipartUploadInvalidPart(t *testing.T) {
|
|
|
|
hc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName, objName := "bucket-to-upload-part", "object-multipart"
|
|
|
|
createTestBucket(hc, bktName)
|
|
|
|
partSize := 8 // less than min part size
|
|
|
|
|
|
|
|
multipartUpload := createMultipartUpload(hc, bktName, objName, map[string]string{})
|
|
|
|
etag1, _ := uploadPart(hc, bktName, objName, multipartUpload.UploadID, 1, partSize)
|
|
|
|
etag2, _ := uploadPart(hc, bktName, objName, multipartUpload.UploadID, 2, partSize)
|
|
|
|
w := completeMultipartUploadBase(hc, bktName, objName, multipartUpload.UploadID, []string{etag1, etag2})
|
|
|
|
assertS3Error(hc.t, w, s3Errors.GetAPIError(s3Errors.ErrEntityTooSmall))
|
|
|
|
}
|