Marina Biryukova
b28ecef43b
All checks were successful
/ Vulncheck (pull_request) Successful in 9m5s
/ Lint (pull_request) Successful in 11m1s
/ Tests (1.20) (pull_request) Successful in 9m59s
/ Tests (1.21) (pull_request) Successful in 9m53s
/ DCO (pull_request) Successful in 11m34s
/ Builds (1.20) (pull_request) Successful in 12m24s
/ Builds (1.21) (pull_request) Successful in 8m59s
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
48 lines
1.6 KiB
Go
48 lines
1.6 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/hex"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetObjectPartsAttributes(t *testing.T) {
|
|
hc := prepareHandlerContext(t)
|
|
|
|
bktName := "bucket-get-attributes"
|
|
objName, objMultipartName := "object", "object-multipart"
|
|
partSize := 8
|
|
|
|
createTestBucket(hc, bktName)
|
|
|
|
putObject(hc, bktName, objName)
|
|
result := getObjectAttributes(hc, bktName, objName, objectParts)
|
|
require.Nil(t, result.ObjectParts)
|
|
|
|
multipartUpload := createMultipartUpload(hc, bktName, objMultipartName, map[string]string{})
|
|
etag, _ := uploadPart(hc, bktName, objMultipartName, multipartUpload.UploadID, 1, partSize)
|
|
completeMultipartUpload(hc, bktName, objMultipartName, multipartUpload.UploadID, []string{etag})
|
|
etagBytes, err := hex.DecodeString(etag[1 : len(etag)-1])
|
|
require.NoError(t, err)
|
|
|
|
result = getObjectAttributes(hc, bktName, objMultipartName, objectParts)
|
|
require.NotNil(t, result.ObjectParts)
|
|
require.Len(t, result.ObjectParts.Parts, 1)
|
|
require.Equal(t, base64.StdEncoding.EncodeToString(etagBytes), result.ObjectParts.Parts[0].ChecksumSHA256)
|
|
require.Equal(t, partSize, result.ObjectParts.Parts[0].Size)
|
|
require.Equal(t, 1, result.ObjectParts.PartsCount)
|
|
}
|
|
|
|
func getObjectAttributes(hc *handlerContext, bktName, objName string, attrs ...string) *GetObjectAttributesResponse {
|
|
w, r := prepareTestRequest(hc, bktName, objName, nil)
|
|
r.Header.Set(api.AmzObjectAttributes, strings.Join(attrs, ","))
|
|
hc.Handler().GetObjectAttributesHandler(w, r)
|
|
result := &GetObjectAttributesResponse{}
|
|
parseTestResponse(hc.t, w, result)
|
|
|
|
return result
|
|
}
|