2022-06-01 09:54:27 +00:00
|
|
|
package handler
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api"
|
|
|
|
"github.com/nspcc-dev/neofs-s3-gw/api/layer"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetObjectPartsAttributes(t *testing.T) {
|
|
|
|
hc := prepareHandlerContext(t)
|
|
|
|
|
|
|
|
bktName := "bucket-get-attributes"
|
|
|
|
objName, objMultipartName := "object", "object-multipart"
|
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
createTestBucket(hc, bktName)
|
2022-06-01 09:54:27 +00:00
|
|
|
|
|
|
|
body := bytes.NewReader([]byte("content"))
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r := prepareTestPayloadRequest(hc, bktName, objName, body)
|
2022-06-01 09:54:27 +00:00
|
|
|
hc.Handler().PutObjectHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusOK)
|
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r = prepareTestRequest(hc, bktName, objName, nil)
|
2022-06-01 09:54:27 +00:00
|
|
|
r.Header.Set(api.AmzObjectAttributes, objectParts)
|
|
|
|
hc.Handler().GetObjectAttributesHandler(w, r)
|
|
|
|
result := &GetObjectAttributesResponse{}
|
|
|
|
parseTestResponse(t, w, result)
|
|
|
|
require.Nil(t, result.ObjectParts)
|
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r = prepareTestRequest(hc, bktName, objMultipartName, nil)
|
2022-06-01 09:54:27 +00:00
|
|
|
hc.Handler().CreateMultipartUploadHandler(w, r)
|
|
|
|
multipartUpload := &InitiateMultipartUploadResponse{}
|
|
|
|
parseTestResponse(t, w, multipartUpload)
|
|
|
|
|
|
|
|
body2 := bytes.NewReader([]byte("content2"))
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r = prepareTestPayloadRequest(hc, bktName, objMultipartName, body2)
|
2022-06-01 09:54:27 +00:00
|
|
|
query := make(url.Values)
|
|
|
|
query.Add(uploadIDHeaderName, multipartUpload.UploadID)
|
|
|
|
query.Add(partNumberHeaderName, "1")
|
|
|
|
r.URL.RawQuery = query.Encode()
|
|
|
|
hc.Handler().UploadPartHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusOK)
|
|
|
|
etag := w.Result().Header.Get(api.ETag)
|
|
|
|
|
|
|
|
completeUpload := &CompleteMultipartUpload{
|
|
|
|
Parts: []*layer.CompletedPart{{
|
|
|
|
ETag: etag,
|
|
|
|
PartNumber: 1,
|
|
|
|
}},
|
|
|
|
}
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r = prepareTestRequest(hc, bktName, objMultipartName, completeUpload)
|
2022-06-01 09:54:27 +00:00
|
|
|
query = make(url.Values)
|
|
|
|
query.Add(uploadIDHeaderName, multipartUpload.UploadID)
|
|
|
|
r.URL.RawQuery = query.Encode()
|
|
|
|
hc.Handler().CompleteMultipartUploadHandler(w, r)
|
|
|
|
assertStatus(t, w, http.StatusOK)
|
|
|
|
|
2022-10-04 08:31:09 +00:00
|
|
|
w, r = prepareTestRequest(hc, bktName, objMultipartName, nil)
|
2022-06-01 09:54:27 +00:00
|
|
|
r.Header.Set(api.AmzObjectAttributes, objectParts)
|
|
|
|
hc.Handler().GetObjectAttributesHandler(w, r)
|
|
|
|
result = &GetObjectAttributesResponse{}
|
|
|
|
parseTestResponse(t, w, result)
|
|
|
|
require.NotNil(t, result.ObjectParts)
|
2022-06-02 15:26:26 +00:00
|
|
|
require.Len(t, result.ObjectParts.Parts, 1)
|
|
|
|
require.Equal(t, etag, result.ObjectParts.Parts[0].ChecksumSHA256)
|
|
|
|
require.Equal(t, 8, result.ObjectParts.Parts[0].Size)
|
2022-06-01 09:54:27 +00:00
|
|
|
require.Equal(t, 1, result.ObjectParts.PartsCount)
|
|
|
|
}
|