Skip to content
Merged
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
51 changes: 5 additions & 46 deletions .github/workflows/healthchecks_clickhouse_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,49 +29,8 @@ on:

jobs:
build:
runs-on: ubuntu-latest
services:
clickhouse:
image: clickhouse/clickhouse-server:24-alpine
ports:
- 8123:8123
env:
CLICKHOUSE_DB: default
CLICKHOUSE_USER: default
CLICKHOUSE_PASSWORD: "Password12!"
CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: "1"
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.ClickHouse/HealthChecks.ClickHouse.csproj &&
dotnet restore ./test/HealthChecks.ClickHouse.Tests/HealthChecks.ClickHouse.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.ClickHouse/HealthChecks.ClickHouse.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.ClickHouse.Tests/HealthChecks.ClickHouse.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.ClickHouse/HealthChecks.ClickHouse.csproj &&
dotnet build --no-restore ./test/HealthChecks.ClickHouse.Tests/HealthChecks.ClickHouse.Tests.csproj
- name: Test
run: >
dotnet test
./test/HealthChecks.ClickHouse.Tests/HealthChecks.ClickHouse.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: ClickHouse
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.ClickHouse/HealthChecks.ClickHouse.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.ClickHouse.Tests/HealthChecks.ClickHouse.Tests.csproj
CODECOV_FLAGS: ClickHouse
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<PackageVersion Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageVersion Include="System.Threading.Channels" Version="8.0.0" />
<PackageVersion Include="Testcontainers" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.ClickHouse" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Kafka" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Milvus" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="$(TestcontainersVersion)" />
Expand Down
39 changes: 39 additions & 0 deletions test/HealthChecks.ClickHouse.Tests/ClickHouseContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Testcontainers.ClickHouse;

namespace HealthChecks.ClickHouse.Tests;

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

private const string Image = "library/clickhouse";

private const string Tag = "25.7.2";

public ClickHouseContainer? Container { get; private set; }

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

return Container.GetConnectionString();
}

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

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

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

await container.StartAsync();

return container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ public class DBConfigSetting
public string ConnectionString { get; set; } = null!;
}

public class ClickHouse_healthcheck_should
public class ClickHouse_healthcheck_should(ClickHouseContainerFixture clickHouseFixture) : IClassFixture<ClickHouseContainerFixture>
{
private const string ConnectionString = "Host=127.0.0.1;Port=8123;Database=default;Username=default;Password=Password12!;";
private readonly string _connectionString = clickHouseFixture.GetConnectionString();

[Fact]
public async Task be_healthy_if_ClickHouse_is_available()
{
var webHostBuilder = new WebHostBuilder()
.ConfigureServices(static services =>
.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddClickHouse(static _ => new ClickHouseConnection(ConnectionString), tags: new string[] { "ClickHouse" });
.AddClickHouse(_ => new ClickHouseConnection(_connectionString), tags: new string[] { "ClickHouse" });
})
.Configure(static app =>
{
Expand All @@ -42,10 +42,10 @@ public async Task be_healthy_if_ClickHouse_is_available()
public async Task be_unhealthy_if_sql_query_is_not_valid()
{
var webHostBuilder = new WebHostBuilder()
.ConfigureServices(static services =>
.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddClickHouse(static _ => new ClickHouseConnection(ConnectionString), "SELECT 1 FROM InvalidDB", tags: new string[] { "ClickHouse" });
.AddClickHouse(_ => new ClickHouseConnection(_connectionString), "SELECT 1 FROM InvalidDB", tags: new string[] { "ClickHouse" });
})
.Configure(static app =>
{
Expand All @@ -68,8 +68,11 @@ public async Task be_unhealthy_if_ClickHouse_is_not_available()
var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddClickHouse(static _ => new ClickHouseConnection("Host=200.0.0.1;Port=8123;Database=default;Username=default;Password=Password12!;"), tags: new string[] { "ClickHouse" });
services
.AddHealthChecks()
.AddClickHouse(static _ => new ClickHouseConnection("Host=200.0.0.1;Port=8123;Database=default;Username=default;Password=Password12!;"),
tags: ["ClickHouse"],
timeout: TimeSpan.FromSeconds(15));
})
.Configure(app =>
{
Expand All @@ -94,7 +97,7 @@ public async Task be_healthy_if_ClickHouse_is_available_by_iServiceProvider_regi
{
services.AddSingleton(new DBConfigSetting
{
ConnectionString = ConnectionString
ConnectionString = _connectionString
});

services.AddHealthChecks()
Expand Down Expand Up @@ -126,8 +129,12 @@ public async Task be_unhealthy_if_ClickHouse_is_not_available_registered()
ConnectionString = "Server=200.0.0.1;Port=8010;User ID=postgres;Password=Password12!;database=postgres"
});

services.AddHealthChecks()
.AddClickHouse(static sp => new ClickHouseConnection(sp.GetRequiredService<DBConfigSetting>().ConnectionString), tags: new string[] { "ClickHouse" });
services
.AddHealthChecks()
.AddClickHouse(
static sp => new ClickHouseConnection(sp.GetRequiredService<DBConfigSetting>().ConnectionString),
tags: ["ClickHouse"],
timeout: TimeSpan.FromSeconds(15));
})
.Configure(app =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<ProjectReference Include="..\..\src\HealthChecks.ClickHouse\HealthChecks.ClickHouse.csproj" />
</ItemGroup>

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

</Project>
Loading