Skip to content

Commit

Permalink
client: External statistic tests in net map snapshot
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Baidakov <[email protected]>
  • Loading branch information
smallhive committed Jun 23, 2023
1 parent 0755dd6 commit 2c07ac5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
"github.com/nspcc-dev/neofs-api-go/v2/session"
)

var (
// special variable for test purposes only, to overwrite real RPC calls.
rpcApiNetMapSnapshot = rpcapi.NetMapSnapshot

Check warning on line 15 in client/api.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var rpcApiNetMapSnapshot should be rpcAPINetMapSnapshot (revive)
)

// interface of NeoFS API server. Exists for test purposes only.
type neoFSAPIServer interface {
createSession(cli *client.Client, req *session.CreateRequest, opts ...client.CallOption) (*session.CreateResponse, error)
Expand All @@ -29,7 +34,7 @@ func rpcErr(e error) error {
// executes NetmapService.NetmapSnapshot RPC declared in NeoFS API protocol
// using underlying client.Client.
func (x *coreServer) netMapSnapshot(ctx context.Context, req v2netmap.SnapshotRequest) (*v2netmap.SnapshotResponse, error) {
resp, err := rpcapi.NetMapSnapshot((*client.Client)(x), &req, client.WithContext(ctx))
resp, err := rpcApiNetMapSnapshot((*client.Client)(x), &req, client.WithContext(ctx))
if err != nil {
return nil, rpcErr(err)
}
Expand Down
33 changes: 33 additions & 0 deletions client/container_statistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,36 @@ func TestClient_ContainerEndpointInfoStatistic(t *testing.T) {

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

func TestClient_ContainerNetMapSnapshotStatistic(t *testing.T) {
signer := test.RandomSignerRFC6979(t)
ctx := context.Background()
c := newClient(t, signer, nil)

rpcApiNetMapSnapshot = func(cli *client.Client, req *netmapv2.SnapshotRequest, opts ...client.CallOption) (*netmapv2.SnapshotResponse, error) {
var resp netmapv2.SnapshotResponse
var meta session.ResponseMetaHeader
var netMap netmapv2.NetMap

body := netmapv2.SnapshotResponseBody{}
body.SetNetMap(&netMap)

resp.SetBody(&body)
resp.SetMetaHeader(&meta)

if err := signServiceMessage(signer, &resp); err != nil {
panic(fmt.Sprintf("sign response: %v", err))
}

return &resp, nil
}

collector := newCollector()
c.prm.statisticCallback = collector.Collect
c.setNeoFSAPIServer((*coreServer)(&c.c))

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

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

0 comments on commit 2c07ac5

Please sign in to comment.