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
47 changes: 5 additions & 42 deletions .github/workflows/healthchecks_consul_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,8 @@ on:

jobs:
build:
runs-on: ubuntu-latest
services:
consul:
image: hashicorp/consul:latest
ports:
- 8500:8500
- 8600:8600
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.Consul/HealthChecks.Consul.csproj &&
dotnet restore ./test/HealthChecks.Consul.Tests/HealthChecks.Consul.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.Consul/HealthChecks.Consul.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.Consul.Tests/HealthChecks.Consul.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.Consul/HealthChecks.Consul.csproj &&
dotnet build --no-restore ./test/HealthChecks.Consul.Tests/HealthChecks.Consul.Tests.csproj
- name: Test
run: >
dotnet test
./test/HealthChecks.Consul.Tests/HealthChecks.Consul.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: Consul
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.Consul/HealthChecks.Consul.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.Consul.Tests/HealthChecks.Consul.Tests.csproj
CODECOV_FLAGS: Consul
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
<PackageVersion Include="Testcontainers" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.ClickHouse" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Consul" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Kafka" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Milvus" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="$(TestcontainersVersion)" />
Expand Down
44 changes: 44 additions & 0 deletions test/HealthChecks.Consul.Tests/ConsulContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Testcontainers.Consul;

namespace HealthChecks.Consul.Tests;

public class ConsulContainerFixture : IAsyncLifetime
{
private const string Registry = "docker.io";

private const string Image = "library/consul";

private const string Tag = "1.15.4";

public ConsulContainer? Container { get; private set; }

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

return new ConsulOptions
{
HostName = Container.Hostname,
Port = Container.GetMappedPublicPort(ConsulBuilder.ConsulHttpPort),
RequireHttps = false
};
}

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

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

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

await container.StartAsync();

return container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

namespace HealthChecks.Consul.Tests.Functional;

public class consul_healthcheck_should
public class consul_healthcheck_should(ConsulContainerFixture consulFixture) : IClassFixture<ConsulContainerFixture>
{
[Fact]
public async Task be_healthy_if_consul_is_available()
{
var options = consulFixture.GetConnectionOptions();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddConsul(setup =>
{
setup.HostName = "localhost";
setup.Port = 8500;
setup.RequireHttps = false;
setup.HostName = options.HostName;
setup.Port = options.Port;
setup.RequireHttps = options.RequireHttps;
}, tags: ["consul"]);
})
.Configure(app =>
Expand All @@ -36,15 +38,17 @@ public async Task be_healthy_if_consul_is_available()
[Fact]
public async Task be_unhealthy_if_consul_is_not_available()
{
var options = consulFixture.GetConnectionOptions();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddConsul(setup =>
{
setup.HostName = "non-existing-host";
setup.Port = 8500;
setup.RequireHttps = false;
setup.Port = options.Port;
setup.RequireHttps = options.RequireHttps;
}, tags: ["consul"]);
})
.Configure(app =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<ProjectReference Include="..\..\src\HealthChecks.Consul\HealthChecks.Consul.csproj" />
</ItemGroup>

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

</Project>