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

jobs:
build:
runs-on: ubuntu-latest
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.InfluxDB/HealthChecks.InfluxDB.csproj &&
dotnet restore ./test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj || (echo "Run 'dotnet format' to fix whitespace issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj || (echo "Run 'dotnet format' to fix analyzers issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj &&
dotnet build --no-restore ./test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj
- name: Setup InfluxDB
uses: maikebing/influxdb-action@v5
with:
influxdb_version: 2.7.1
influxdb_org: influxdata
influxdb_user: ci_user
influxdb_password: password
influxdb_bucket: dummy
- name: Test
run: >
dotnet test
./test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.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: InfluxDB
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.InfluxDB/HealthChecks.InfluxDB.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj
CODECOV_FLAGS: InfluxDB
3 changes: 2 additions & 1 deletion 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.InfluxDb" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Kafka" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Milvus" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.PostgreSql" 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,17 +2,19 @@

namespace HealthChecks.InfluxDB.Tests.Functional;

public class influxdb_healthcheck_should
public class influxdb_healthcheck_should(InfluxDBContainerFixture influxDBFixture) : IClassFixture<InfluxDBContainerFixture>
{
[Fact]
public async Task be_healthy_if_influxdb_is_available()
{
var properties = influxDBFixture.GetConnectionProperties();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services
.AddHealthChecks()
.AddInfluxDB("http://localhost:8086/?org=influxdata&bucket=dummy&latest=-72h", "ci_user", "password", "influxdb", tags: ["influxdb"]);
.AddInfluxDB(properties.Address, properties.Username, properties.Password, "influxdb", tags: ["influxdb"]);
})
.Configure(app =>
{
Expand All @@ -32,12 +34,14 @@ public async Task be_healthy_if_influxdb_is_available()
[Fact]
public async Task be_unhealthy_if_influxdb_is_unavailable()
{
var properties = influxDBFixture.GetConnectionProperties();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services
.AddHealthChecks()
.AddInfluxDB("http://localhost:8086/?org=influxdata&bucket=dummy&latest=-72h", "ci_user_unavailable", "password", "influxdb", tags: ["influxdb"]);
.AddInfluxDB(properties.Address, "invalid_user", properties.Password, "influxdb", tags: ["influxdb"]);
})
.Configure(app =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<ProjectReference Include="..\..\src\HealthChecks.InfluxDB\HealthChecks.InfluxDB.csproj" />
</ItemGroup>

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

</Project>
39 changes: 39 additions & 0 deletions test/HealthChecks.InfluxDB.Tests/InfluxDBContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using Testcontainers.InfluxDb;

namespace HealthChecks.InfluxDB.Tests;

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

private const string Image = "library/influxdb";

private const string Tag = "2.7.12-alpine";

public InfluxDbContainer? Container { get; private set; }

public (string Address, string Username, string Password) GetConnectionProperties()
{
if (Container is null)
{
throw new InvalidOperationException("The test container was not initialized.");
}

return (Container.GetAddress(), InfluxDbBuilder.DefaultUsername, InfluxDbBuilder.DefaultPassword);
}

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

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

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

await container.StartAsync();

return container;
}
}