Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 5 additions & 41 deletions .github/workflows/healthchecks_openidconnectserver_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,44 +29,8 @@ on:

jobs:
build:
runs-on: ubuntu-latest
services:
idsvr:
image: nakah/identityserver4
ports:
- 8888:80
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
8.0.x
9.0.x
- name: Restore
run: |
dotnet restore ./src/HealthChecks.OpenIdConnectServer/HealthChecks.OpenIdConnectServer.csproj &&
dotnet restore ./test/HealthChecks.OpenIdConnectServer.Tests/HealthChecks.OpenIdConnectServer.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.OpenIdConnectServer/HealthChecks.OpenIdConnectServer.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.OpenIdConnectServer.Tests/HealthChecks.OpenIdConnectServer.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.OpenIdConnectServer/HealthChecks.OpenIdConnectServer.csproj &&
dotnet build --no-restore ./test/HealthChecks.OpenIdConnectServer.Tests/HealthChecks.OpenIdConnectServer.Tests.csproj
- name: Test
run: >
dotnet test
./test/HealthChecks.OpenIdConnectServer.Tests/HealthChecks.OpenIdConnectServer.Tests.csproj
--no-restore
--no-build
--collect "XPlat Code Coverage"
--results-directory .coverage
--
DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
- name: Upload Coverage
uses: codecov/codecov-action@v5
with:
flags: OpenIdConnectServer
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.OpenIdConnectServer/HealthChecks.OpenIdConnectServer.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.OpenIdConnectServer.Tests/HealthChecks.OpenIdConnectServer.Tests.csproj
CODECOV_FLAGS: OpenIdConnectServer
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<PackageVersion Include="Testcontainers" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.ClickHouse" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Kafka" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Keycloak" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Milvus" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="$(TestcontainersVersion)" />
<PackageVersion Include="TestContainers.MongoDb" Version="$(TestcontainersVersion)" />
Expand All @@ -119,4 +120,4 @@
<ItemGroup Condition="'$(IsPackable)' == 'true'">
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace HealthChecks.OpenIdConnectServer.Tests.Functional;

public class oidc_server_healthcheck_should
public class oidc_server_healthcheck_should(KeycloakContainerFixture keycloakFixture) : IClassFixture<KeycloakContainerFixture>
{
[Fact]
public async Task be_unhealthy_if_oidc_server_is_unavailable()
Expand Down Expand Up @@ -32,12 +32,14 @@ public async Task be_unhealthy_if_oidc_server_is_unavailable()
[Fact]
public async Task be_healthy_if_oidc_server_is_available()
{
string baseAddress = keycloakFixture.GetBaseAddress();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services
.AddHealthChecks()
.AddOpenIdConnectServer(new Uri("http://localhost:8888"), tags: ["oidcserver"]);
.AddOpenIdConnectServer(new Uri(baseAddress), tags: ["oidcserver"]);
})
.Configure(app =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<ProjectReference Include="..\..\src\HealthChecks.OpenIdConnectServer\HealthChecks.OpenIdConnectServer.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Testcontainers.Keycloak" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Testcontainers.Keycloak;

namespace HealthChecks.OpenIdConnectServer.Tests;

public class KeycloakContainerFixture : IAsyncLifetime
{
private const string Registry = "quay.io";

private const string Image = "keycloak/keycloak";

private const string Tag = "26.3.2";

public KeycloakContainer? Container { get; private set; }

public string GetBaseAddress()
{
if (Container is null)
{
throw new InvalidOperationException("The test container was not initialized.");
}

var uriBuilder = new UriBuilder(Container.GetBaseAddress())
{
Path = "/realms/master/"
};

return uriBuilder.ToString();
}

public async Task InitializeAsync() => Container = await CreateContainerAsync();

public Task DisposeAsync() => Container?.DisposeAsync().AsTask() ?? Task.CompletedTask;

private static async Task<KeycloakContainer> CreateContainerAsync()
{
var container = new KeycloakBuilder()
.WithImage($"{Registry}/{Image}:{Tag}")
.Build();

await container.StartAsync();

return container;
}
}
Loading