-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathRpcExceptionDestructurerTest.cs
59 lines (48 loc) · 2.62 KB
/
RpcExceptionDestructurerTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
namespace Serilog.Exceptions.Test.Destructurers;
using System;
using System.Net;
using global::Grpc.Core;
using Serilog.Exceptions.Core;
using Serilog.Exceptions.Grpc.Destructurers;
using Xunit;
using static LogJsonOutputUtils;
public class RpcExceptionDestructurerTest
{
[Fact]
public void RpcException_StatusCodeIsLoggedAsProperty()
{
var options = new DestructuringOptionsBuilder().WithDestructurers(new[] { new RpcExceptionDestructurer() });
var rpcException = new RpcException(new Status(StatusCode.Aborted, string.Empty));
Test_LoggedExceptionContainsProperty(rpcException, nameof(RpcException.Status.StatusCode), nameof(StatusCode.Aborted), options);
}
[Fact]
public void RpcException_StatusDetailIsLoggedAsProperty()
{
var options = new DestructuringOptionsBuilder().WithDestructurers(new[] { new RpcExceptionDestructurer() });
var testDetail = "details";
var rpcException = new RpcException(new Status(StatusCode.Aborted, testDetail));
Test_LoggedExceptionContainsProperty(rpcException, nameof(RpcException.Status.Detail), testDetail, options);
}
[Fact]
public void RpcException_TrailersAreLoggedAsProperty()
{
var options = new DestructuringOptionsBuilder().WithDestructurers(new[] { new RpcExceptionDestructurer() });
const string stringTrailerKey1 = "key1";
const string stringTrailerValue1 = "stringTrailerValue1";
const string stringTrailerKey2 = "key2";
const string stringTrailerValue2 = "stringTrailerValue2";
var metadata = new Metadata { { stringTrailerKey1, stringTrailerValue1 }, { stringTrailerKey2, stringTrailerValue2 } };
var rpcException = new RpcException(new Status(StatusCode.Aborted, string.Empty), metadata);
Test_LoggedExceptionContainsProperty(rpcException, $"{nameof(RpcException.Trailers)}.{stringTrailerKey1}", stringTrailerValue1, options);
Test_LoggedExceptionContainsProperty(rpcException, $"{nameof(RpcException.Trailers)}.{stringTrailerKey2}", stringTrailerValue2, options);
}
[Fact]
public void RpcException_BinaryTrailersAreNotLoggedAsProperty()
{
var options = new DestructuringOptionsBuilder().WithDestructurers(new[] { new RpcExceptionDestructurer() });
const string stringTrailerKey1 = "key-bin";
var metadata = new Metadata { { stringTrailerKey1, new byte[] { 1 } } };
var rpcException = new RpcException(new Status(StatusCode.Aborted, string.Empty), metadata);
Test_LoggedExceptionDoesNotContainProperty(rpcException, $"{nameof(RpcException.Trailers)}.{stringTrailerKey1}", options);
}
}