[#16] Client: Unit tests

Signed-off-by: Pavel Gross <p.gross@yando.com>
This commit is contained in:
Pavel Gross 2024-08-16 12:09:17 +03:00
parent 2a28806ace
commit 22e2a53551
6 changed files with 544 additions and 25 deletions

View file

@ -3,24 +3,40 @@ using FrostFS.Netmap;
using Grpc.Core;
using FrostFS.SDK.ClientV2;
using Google.Protobuf;
using FrostFS.SDK.ModelsV2;
namespace FrostFS.SDK.Tests;
public class NetworkMocker(string key) : ServiceBase(key)
{
private static readonly string[] parameterKeys = [
internal static readonly string[] ParameterKeys = [
"AuditFee",
"BasicIncomeRate",
"ContainerFee",
"ContainerAliasFee",
"EpochDuration",
"IRCandidateFee",
"InnerRingCandidateFee",
"MaxECDataCount",
"MaxECParityCount",
"MaxObjectSize",
"WithdrawalFee",
"WithdrawFee",
"HomomorphicHashingDisabled",
"MaintenanceModeAllowed" ];
"MaintenanceModeAllowed"
];
public Dictionary<string, byte[]>? Parameters { get; set; }
public LocalNodeInfoResponse NodeInfoResponse { get; set; }
public LocalNodeInfoRequest LocalNodeInfoRequest { get; set; }
public NetworkInfoRequest NetworkInfoRequest { get; set; }
public NetmapSnapshotResponse NetmapSnapshotResponse { get; set; }
public NetmapSnapshotRequest NetmapSnapshotRequest { get; set; }
public Mock<NetmapService.NetmapServiceClient> GetMock()
{
var mock = new Mock<NetmapService.NetmapServiceClient>();
@ -29,7 +45,7 @@ public class NetworkMocker(string key) : ServiceBase(key)
var networkConfig = new NetworkConfig();
foreach (var key in parameterKeys)
foreach (var key in ParameterKeys)
{
networkConfig.Parameters.Add(new NetworkConfig.Types.Parameter
{
@ -62,7 +78,10 @@ public class NetworkMocker(string key) : ServiceBase(key)
It.IsAny<CancellationToken>()))
.Returns((NetworkInfoRequest r, Metadata m, DateTime? dt, CancellationToken ct) =>
{
Verifier.CheckRequest(r);
NetworkInfoRequest = r;
Metadata = m;
DateTime = dt;
CancellationToken = ct;
return new AsyncUnaryCall<NetworkInfoResponse>(
Task.FromResult(response),
@ -72,6 +91,58 @@ public class NetworkMocker(string key) : ServiceBase(key)
() => { });
});
if (NodeInfoResponse != null)
{
NodeInfoResponse.MetaHeader = ResponseMetaHeader;
NodeInfoResponse.VerifyHeader = GetResponseVerificationHeader(NodeInfoResponse);
mock.Setup(x => x.LocalNodeInfoAsync(
It.IsAny<LocalNodeInfoRequest>(),
It.IsAny<Metadata>(),
It.IsAny<DateTime?>(),
It.IsAny<CancellationToken>()))
.Returns((LocalNodeInfoRequest r, Metadata m, DateTime? dt, CancellationToken ct) =>
{
LocalNodeInfoRequest = r;
Metadata = m;
DateTime = dt;
CancellationToken = ct;
return new AsyncUnaryCall<LocalNodeInfoResponse>(
Task.FromResult(NodeInfoResponse),
Task.FromResult(ResponseMetaData),
() => new Grpc.Core.Status(StatusCode.OK, string.Empty),
() => ResponseMetaData,
() => { });
});
}
if (NetmapSnapshotResponse != null)
{
NetmapSnapshotResponse.MetaHeader = ResponseMetaHeader;
NetmapSnapshotResponse.VerifyHeader = GetResponseVerificationHeader(NetmapSnapshotResponse);
mock.Setup(x => x.NetmapSnapshotAsync(
It.IsAny<NetmapSnapshotRequest>(),
It.IsAny<Metadata>(),
It.IsAny<DateTime?>(),
It.IsAny<CancellationToken>()))
.Returns((NetmapSnapshotRequest r, Metadata m, DateTime? dt, CancellationToken ct) =>
{
NetmapSnapshotRequest = r;
Metadata = m;
DateTime = dt;
CancellationToken = ct;
return new AsyncUnaryCall<NetmapSnapshotResponse>(
Task.FromResult(NetmapSnapshotResponse),
Task.FromResult(ResponseMetaData),
() => new Grpc.Core.Status(StatusCode.OK, string.Empty),
() => ResponseMetaData,
() => { });
});
}
return mock;
}
}