diff --git a/.github/workflows/healthchecks_influxdb_ci.yml b/.github/workflows/healthchecks_influxdb_ci.yml index 1e554c42b5..64b70489c8 100644 --- a/.github/workflows/healthchecks_influxdb_ci.yml +++ b/.github/workflows/healthchecks_influxdb_ci.yml @@ -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 diff --git a/Directory.Packages.props b/Directory.Packages.props index 2c2207765a..6f665e0117 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -104,6 +104,7 @@ + @@ -119,4 +120,4 @@ - + \ No newline at end of file diff --git a/test/HealthChecks.InfluxDB.Tests/Functional/InfluxDBHealthCheckTests.cs b/test/HealthChecks.InfluxDB.Tests/Functional/InfluxDBHealthCheckTests.cs index 1df8dad343..418470b943 100644 --- a/test/HealthChecks.InfluxDB.Tests/Functional/InfluxDBHealthCheckTests.cs +++ b/test/HealthChecks.InfluxDB.Tests/Functional/InfluxDBHealthCheckTests.cs @@ -2,17 +2,19 @@ namespace HealthChecks.InfluxDB.Tests.Functional; -public class influxdb_healthcheck_should +public class influxdb_healthcheck_should(InfluxDBContainerFixture influxDBFixture) : IClassFixture { [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 => { @@ -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 => { diff --git a/test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj b/test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj index 3325da8bcb..c741dc69be 100644 --- a/test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj +++ b/test/HealthChecks.InfluxDB.Tests/HealthChecks.InfluxDB.Tests.csproj @@ -4,4 +4,8 @@ + + + + diff --git a/test/HealthChecks.InfluxDB.Tests/InfluxDBContainerFixture.cs b/test/HealthChecks.InfluxDB.Tests/InfluxDBContainerFixture.cs new file mode 100644 index 0000000000..17dc7e7029 --- /dev/null +++ b/test/HealthChecks.InfluxDB.Tests/InfluxDBContainerFixture.cs @@ -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 CreateContainerAsync() + { + var container = new InfluxDbBuilder() + .WithImage($"{Registry}/{Image}:{Tag}") + .Build(); + + await container.StartAsync(); + + return container; + } +}