Skip to content

Commit

Permalink
client: Increase test coverage of container ops
Browse files Browse the repository at this point in the history
Continues TBD.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 1, 2024
1 parent 0df829c commit a2b4e8a
Show file tree
Hide file tree
Showing 11 changed files with 6,028 additions and 1,060 deletions.
592 changes: 150 additions & 442 deletions client/accounting_test.go

Large diffs are not rendered by default.

944 changes: 927 additions & 17 deletions client/client_test.go

Large diffs are not rendered by default.

201 changes: 0 additions & 201 deletions client/container_statistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ import (
"context"
"crypto/rand"
"io"
mathRand "math/rand/v2"
"strconv"
"testing"
"time"

"github.com/google/uuid"
"github.com/nspcc-dev/neofs-sdk-go/container"
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
"github.com/nspcc-dev/neofs-sdk-go/eacl"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
"github.com/nspcc-dev/neofs-sdk-go/object"
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
reputation2 "github.com/nspcc-dev/neofs-sdk-go/reputation"
session2 "github.com/nspcc-dev/neofs-sdk-go/session"
"github.com/nspcc-dev/neofs-sdk-go/stat"
"github.com/nspcc-dev/neofs-sdk-go/user"
Expand Down Expand Up @@ -91,126 +87,6 @@ func prepareContainer(accountID user.ID) container.Container {
return cont
}

func testEaclTable(containerID cid.ID) eacl.Table {
var table eacl.Table
table.SetCID(containerID)

r := eacl.ConstructRecord(eacl.ActionAllow, eacl.OperationPut, []eacl.Target{eacl.NewTargetByRole(eacl.RoleOthers)})
table.AddRecord(&r)

return table
}

func TestClientStatistic_ContainerPut(t *testing.T) {
usr := usertest.User()
ctx := context.Background()
var srv testPutContainerServer
c := newTestContainerClient(t, &srv)
cont := prepareContainer(usr.ID)

collector := newCollector()
c.prm.statisticCallback = collector.Collect

var prm PrmContainerPut
_, err := c.ContainerPut(ctx, cont, usr.RFC6979, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodContainerPut].requests)
}

func TestClientStatistic_ContainerGet(t *testing.T) {
ctx := context.Background()
var srv testGetContainerServer
c := newTestContainerClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

var prm PrmContainerGet
_, err := c.ContainerGet(ctx, cid.ID{}, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodContainerGet].requests)
}

func TestClientStatistic_ContainerList(t *testing.T) {
usr := usertest.User()
ctx := context.Background()
var srv testListContainersServer
c := newTestContainerClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

var prm PrmContainerList
_, err := c.ContainerList(ctx, usr.ID, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodContainerList].requests)
}

func TestClientStatistic_ContainerDelete(t *testing.T) {
usr := usertest.User()
ctx := context.Background()
var srv testDeleteContainerServer
c := newTestContainerClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

var prm PrmContainerDelete
err := c.ContainerDelete(ctx, cid.ID{}, usr, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodContainerDelete].requests)
}

func TestClientStatistic_ContainerEacl(t *testing.T) {
ctx := context.Background()
var srv testGetEACLServer
c := newTestContainerClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

var prm PrmContainerEACL
_, err := c.ContainerEACL(ctx, cid.ID{}, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodContainerEACL].requests)
}

func TestClientStatistic_ContainerSetEacl(t *testing.T) {
usr := usertest.User()
ctx := context.Background()
var srv testSetEACLServer
c := newTestContainerClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

var prm PrmContainerSetEACL
table := testEaclTable(cidtest.ID())
err := c.ContainerSetEACL(ctx, table, usr, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodContainerSetEACL].requests)
}

func TestClientStatistic_ContainerAnnounceUsedSpace(t *testing.T) {
ctx := context.Background()
var srv testAnnounceContainerSpaceServer
c := newTestContainerClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

estimation := container.SizeEstimation{}
estimation.SetContainer(cidtest.ID())
estimation.SetValue(mathRand.Uint64())
estimation.SetEpoch(mathRand.Uint64())

var prm PrmAnnounceSpace
err := c.ContainerAnnounceUsedSpace(ctx, []container.SizeEstimation{estimation}, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodContainerAnnounceUsedSpace].requests)
}

func TestClientStatistic_ContainerSyncContainerWithNetwork(t *testing.T) {
usr := usertest.User()
ctx := context.Background()
Expand All @@ -227,48 +103,6 @@ func TestClientStatistic_ContainerSyncContainerWithNetwork(t *testing.T) {
require.Equal(t, 1, collector.methods[stat.MethodNetworkInfo].requests)
}

func TestClientStatistic_ContainerEndpointInfo(t *testing.T) {
ctx := context.Background()
srv := newTestGetNodeInfoServer()
c := newTestNetmapClient(t, srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

_, err := c.EndpointInfo(ctx, PrmEndpointInfo{})
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodEndpointInfo].requests)
}

func TestClientStatistic_ContainerNetMapSnapshot(t *testing.T) {
ctx := context.Background()
var srv testNetmapSnapshotServer
c := newTestNetmapClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

_, err := c.NetMapSnapshot(ctx, PrmNetMapSnapshot{})
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodNetMapSnapshot].requests)
}

func TestClientStatistic_CreateSession(t *testing.T) {
usr := usertest.User()
ctx := context.Background()
var srv testCreateSessionServer
c := newTestSessionClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

var prm PrmSessionCreate

_, err := c.SessionCreate(ctx, usr, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodSessionCreate].requests)
}

func TestClientStatistic_ObjectPut(t *testing.T) {
usr := usertest.User()
ctx := context.Background()
Expand Down Expand Up @@ -434,38 +268,3 @@ func TestClientStatistic_ObjectSearch(t *testing.T) {

require.Equal(t, 1, collector.methods[stat.MethodObjectSearch].requests)
}

func TestClientStatistic_AnnounceIntermediateTrust(t *testing.T) {
ctx := context.Background()
var srv testAnnounceIntermediateReputationServer
c := newTestReputationClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

var trust reputation2.PeerToPeerTrust
var prm PrmAnnounceIntermediateTrust

err := c.AnnounceIntermediateTrust(ctx, 1, trust, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodAnnounceIntermediateTrust].requests)
}

func TestClientStatistic_MethodAnnounceLocalTrust(t *testing.T) {
ctx := context.Background()
var srv testAnnounceLocalTrustServer
c := newTestReputationClient(t, &srv)
collector := newCollector()
c.prm.statisticCallback = collector.Collect

var peer reputation2.PeerID
var trust reputation2.Trust
trust.SetPeer(peer)

var prm PrmAnnounceLocalTrust

err := c.AnnounceLocalTrust(ctx, 1, []reputation2.Trust{trust}, prm)
require.NoError(t, err)

require.Equal(t, 1, collector.methods[stat.MethodAnnounceLocalTrust].requests)
}
Loading

0 comments on commit a2b4e8a

Please sign in to comment.