Skip to content

Commit

Permalink
test: Update to Rego v1 + add explicit --addr param for OPA fixture. (
Browse files Browse the repository at this point in the history
#27)

Also included: GH Actions workflow update for .NET 8.x.

Signed-off-by: Philip Conrad <[email protected]>
  • Loading branch information
philipaconrad authored Jan 9, 2025
1 parent 968c9b4 commit ec4af69
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
13 changes: 11 additions & 2 deletions .github/workflows/01_build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: true

# When a new revision is pushed to a PR, cancel all in-progress CI runs for that
# PR. See https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
build:
name: Build
Expand All @@ -18,7 +24,7 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: "6.0.x"
dotnet-version: "8.x"
- name: Install dependencies
run: dotnet restore
- name: Build
Expand All @@ -34,11 +40,14 @@ jobs:
- name: Setup dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: "6.0.x"
dotnet-version: "8.x"
- name: Install dependencies
run: dotnet restore
- name: Test
run: dotnet test
env:
EOPA_LICENSE_TOKEN: ${{ secrets.EOPA_LICENSE_TOKEN }}
timeout-minutes: 5

release-reqs-check:
name: Release requirements check
Expand Down
3 changes: 2 additions & 1 deletion test/Styra.Opa.AspNetCore.Tests/EOPAContainerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,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
8 changes: 7 additions & 1 deletion test/Styra.Opa.AspNetCore.Tests/OPAContainerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task InitializeAsync()
"testdata/simple/policy.rego",
"testdata/simple/system.rego",
};
string[] opaCmd = { "run", "--server" };
string[] opaCmd = { "run", "--server", "--addr=0.0.0.0:8181" };
var startupCommand = new List<string>().Concat(opaCmd).Concat(startupFiles).ToArray();

// Create a new instance of a container.
Expand All @@ -24,6 +24,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 @@ -34,6 +36,10 @@ 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
2 changes: 2 additions & 0 deletions test/Styra.Opa.AspNetCore.Tests/testdata/simple/policy.rego
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package policy

import rego.v1

echo := {
"decision": true,
"context": {
Expand Down
6 changes: 4 additions & 2 deletions test/Styra.Opa.AspNetCore.Tests/testdata/simple/system.rego
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package system

import rego.v1

# This is used to exercise the default query functionality.

msg := "this is the default path"

main := x {
main := x if {
x := {"msg": msg, "echo": input}
} else {
} else if {
x := {"msg": msg}
}

0 comments on commit ec4af69

Please sign in to comment.