Skip to content

Commit

Permalink
test: Add OutputConsumer settings to fixtures for better debugging. (#97
Browse files Browse the repository at this point in the history
)

In the OPA ASP.NET Core SDK, this setting helped reveal a syntax error
in our Rego that came up because of the OPA v1.0.0 upgrade. If we'd had
that logging in place from the beginning, it could've saved a lot of
time, so we're plumbing it in here for the sake of future maintainers.

Signed-off-by: Philip Conrad <philip@chariot-chaser.net>
  • Loading branch information
philipaconrad authored Jan 9, 2025
1 parent f165ebf commit 3d1b392
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/SmokeTest.Tests/EOPAContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace SmokeTest.Tests;

public class EOPAContainerFixture : IAsyncLifetime
{
// Note: We disable this warning because we control when/how the constructor
Expand Down Expand Up @@ -27,11 +28,12 @@ public async Task InitializeAsync()
// Bind port 8181 of the container to a random port on the host.
.WithPortBinding(8181, true)
.WithCommand(startupCommand)
// Debugging aid, helpful if the Rego files have syntax errors.
.WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole())
// Map our policy and data files into the container instance.
.WithResourceMapping(new DirectoryInfo("testdata"), "/testdata/")
// Wait until the HTTP endpoint of the container is available.
.WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(r => r.ForPort(8181).ForPath("/health")))
//.WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole()) // DEBUG
// Build the container configuration.
.Build();

Expand Down
7 changes: 7 additions & 0 deletions test/SmokeTest.Tests/OPAContainerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public async Task InitializeAsync()
// Bind port 8181 of the container to a random port on the host.
.WithPortBinding(8181, true)
.WithCommand(startupCommand)
// Debugging aid, helpful if the Rego files have syntax errors.
.WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole())
// Map our policy and data files into the container instance.
.WithResourceMapping(new DirectoryInfo("testdata"), "/testdata/")
// Wait until the HTTP endpoint of the container is available.
Expand All @@ -35,6 +37,11 @@ public async Task InitializeAsync()
// Start the container.
await container.StartAsync()
.ConfigureAwait(false);
// DEBUG:
// var (stderr, stdout) = await container.GetLogsAsync(default);
// Console.WriteLine("STDERR: {0}", stderr);
// Console.WriteLine("STDOUT: {0}", stdout);

_container = container;
}
public async Task DisposeAsync()
Expand Down

0 comments on commit 3d1b392

Please sign in to comment.