[#245] v2/container: Add AnnounceUsedSpace method
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
5d9ef5feec
commit
d2ee6b469a
11 changed files with 1351 additions and 185 deletions
|
@ -1,7 +1,9 @@
|
|||
package container_test
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neofs-api-go/v2/acl"
|
||||
|
@ -232,6 +234,38 @@ func TestGetEACLResponseBody_StableMarshal(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAnnounceUsedSpaceRequestBody_StableMarshal(t *testing.T) {
|
||||
requestFrom := generateAnnounceRequestBody(10)
|
||||
transport := new(grpc.AnnounceUsedSpaceRequest_Body)
|
||||
|
||||
t.Run("non empty", func(t *testing.T) {
|
||||
wire, err := requestFrom.StableMarshal(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = goproto.Unmarshal(wire, transport)
|
||||
require.NoError(t, err)
|
||||
|
||||
requestTo := container.AnnounceUsedSpaceRequestBodyFromGRPCMessage(transport)
|
||||
require.Equal(t, requestFrom, requestTo)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAnnounceUsedSpaceResponseBody_StableMarshal(t *testing.T) {
|
||||
responseFrom := generateAnnounceResponseBody()
|
||||
transport := new(grpc.AnnounceUsedSpaceResponse_Body)
|
||||
|
||||
t.Run("non empty", func(t *testing.T) {
|
||||
wire, err := responseFrom.StableMarshal(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = goproto.Unmarshal(wire, transport)
|
||||
require.NoError(t, err)
|
||||
|
||||
responseTo := container.AnnounceUsedSpaceResponseBodyFromGRPCMessage(transport)
|
||||
require.Equal(t, responseFrom, responseTo)
|
||||
})
|
||||
}
|
||||
|
||||
func generateAttribute(k, v string) *container.Attribute {
|
||||
attr := new(container.Attribute)
|
||||
attr.SetKey(k)
|
||||
|
@ -408,3 +442,28 @@ func generateGetEACLResponseBody(n int, k, v string) *container.GetExtendedACLRe
|
|||
|
||||
return resp
|
||||
}
|
||||
|
||||
func generateAnnounceRequestBody(n int) *container.AnnounceUsedSpaceRequestBody {
|
||||
resp := new(container.AnnounceUsedSpaceRequestBody)
|
||||
buf := make([]byte, sha256.Size)
|
||||
|
||||
announcements := make([]*container.UsedSpaceAnnouncement, 0, n)
|
||||
for i := 0; i < n; i++ {
|
||||
rand.Read(buf)
|
||||
|
||||
cid := new(refs.ContainerID)
|
||||
cid.SetValue(buf)
|
||||
|
||||
a := new(container.UsedSpaceAnnouncement)
|
||||
a.SetContainerID(cid)
|
||||
a.SetUsedSpace(rand.Uint64())
|
||||
}
|
||||
|
||||
resp.SetAnnouncements(announcements)
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func generateAnnounceResponseBody() *container.AnnounceUsedSpaceResponseBody {
|
||||
return new(container.AnnounceUsedSpaceResponseBody)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue