Skip to content

Commit 82da8f1

Browse files
committed
feat: Output logs in plugin tests
1 parent 63d1758 commit 82da8f1

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

samples/Grpc/GrpcGreeterClient.Tests/GrpcGreeterClientTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ namespace GrpcGreeterClient.Tests
1515
{
1616
public class GrpcGreeterClientTests : IDisposable
1717
{
18+
private readonly ITestOutputHelper output;
1819
private readonly ISynchronousPluginPactBuilderV4 pact;
1920

2021
public GrpcGreeterClientTests(ITestOutputHelper output)
2122
{
23+
this.output = output;
2224
var config = new PactConfig
2325
{
2426
PactDir = "../../../../pacts/",
@@ -58,6 +60,8 @@ public void ThrowsExceptionWhenNoGrpcClientRequestMade()
5860
{
5961
// No grpc call here results in failure.
6062
}));
63+
64+
this.WriteLogs();
6165
}
6266

6367
[Fact]
@@ -90,6 +94,16 @@ await this.pact.VerifyAsync(async ctx =>
9094
// Assert
9195
greeting.Should().Be("Hello foo");
9296
});
97+
98+
this.WriteLogs();
99+
}
100+
101+
private void WriteLogs()
102+
{
103+
this.output.WriteLine(string.Empty);
104+
this.output.WriteLine("Pact Interaction Logs");
105+
this.output.WriteLine("-----------");
106+
this.output.WriteLine(pact.FetchLogs());
93107
}
94108

95109
public void Dispose() => this.pact?.Dispose();

src/PactNet.Abstractions/ISynchronousPluginPactBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ namespace PactNet;
55
public interface ISynchronousPluginPactBuilderV4 : IPactBuilder, IDisposable
66
{
77
ISynchronousPluginRequestBuilderV4 UponReceiving(string description);
8+
9+
/// <summary>
10+
/// Fetch the interaction logs as a string.
11+
/// </summary>
12+
/// <returns>Logs</returns>
13+
string FetchLogs();
814
}

src/PactNet/SynchronousPluginPactBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using PactNet.Drivers.Plugins;
2+
using PactNet.Interop;
23
using PactNet.Models;
34

45
namespace PactNet;
@@ -16,5 +17,11 @@ public ISynchronousPluginRequestBuilderV4 UponReceiving(string description)
1617
return new SynchronousPluginRequestBuilder(pact.NewSyncInteraction(description));
1718
}
1819

20+
/// <summary>
21+
/// Fetch the interaction logs as a string.
22+
/// </summary>
23+
/// <returns>Logs</returns>
24+
public string FetchLogs() => NativeInterop.FetchLogBuffer(null);
25+
1926
public void Dispose() => pact?.Dispose();
2027
}

0 commit comments

Comments
 (0)