From 2c07ac5a984c65c284b685201ba30951ce828506 Mon Sep 17 00:00:00 2001 From: Evgenii Baidakov Date: Fri, 23 Jun 2023 15:57:19 +0400 Subject: [PATCH] client: External statistic tests in net map snapshot Signed-off-by: Evgenii Baidakov --- client/api.go | 7 ++++++- client/container_statistic_test.go | 33 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/client/api.go b/client/api.go index dfad9ea0..02210375 100644 --- a/client/api.go +++ b/client/api.go @@ -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 +) + // 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) @@ -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) } diff --git a/client/container_statistic_test.go b/client/container_statistic_test.go index 14554042..17d86bbd 100644 --- a/client/container_statistic_test.go +++ b/client/container_statistic_test.go @@ -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) +}