[#441] Don't produce extra object.Head request at regular object upload

Hash can be calculated locally in S3 gateway.
Creation epoch used for versioning and will be
fetched during get and list requests. To avoid
conflicts, put method do not update cache anymore.

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2022-05-19 17:56:42 +03:00 committed by Alex Vanin
parent 2575462daa
commit 385437aace
2 changed files with 61 additions and 21 deletions

View file

@ -1,8 +1,10 @@
package layer
import (
"bytes"
"crypto/rand"
"crypto/sha256"
"io/ioutil"
"testing"
"github.com/nspcc-dev/neofs-s3-gw/api/data"
@ -112,3 +114,21 @@ func TestTrimAfterObjectID(t *testing.T) {
require.Nil(t, actual)
})
}
func TestWrapReader(t *testing.T) {
src := make([]byte, 1024*1024+1)
_, err := rand.Read(src)
require.NoError(t, err)
h := sha256.Sum256(src)
streamHash := sha256.New()
reader := bytes.NewReader(src)
wrappedReader := wrapReader(reader, 64*1024, func(buf []byte) {
streamHash.Write(buf)
})
dst, err := ioutil.ReadAll(wrappedReader)
require.NoError(t, err)
require.Equal(t, src, dst)
require.Equal(t, h[:], streamHash.Sum(nil))
}