Skip to content

Commit

Permalink
Merge branch 'master' into alirexaa/postgres-testscontainers
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik authored Dec 18, 2024
2 parents a0dbc24 + 69fa668 commit feb1fee
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 84 deletions.
42 changes: 5 additions & 37 deletions .github/workflows/healthchecks_redis_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,10 @@ on:
- Directory.Build.props
- Directory.Build.targets
- Directory.Packages.props

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.Redis/HealthChecks.Redis.csproj &&
dotnet restore ./test/HealthChecks.Redis.Tests/HealthChecks.Redis.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.Redis/HealthChecks.Redis.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.Redis.Tests/HealthChecks.Redis.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.Redis/HealthChecks.Redis.csproj &&
dotnet build --no-restore ./test/HealthChecks.Redis.Tests/HealthChecks.Redis.Tests.csproj
- name: Test
run: >
dotnet test
./test/HealthChecks.Redis.Tests/HealthChecks.Redis.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: Redis
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.Redis/HealthChecks.Redis.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.Redis.Tests/HealthChecks.Redis.Tests.csproj
CODECOV_FLAGS: Redis
49 changes: 5 additions & 44 deletions .github/workflows/healthchecks_sqlserver_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
services:
sqlserver:
image: mcr.microsoft.com/mssql/server
ports:
- 5433:1433
env:
ACCEPT_EULA: Y
SA_PASSWORD: Password12!
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.SqlServer/HealthChecks.SqlServer.csproj &&
dotnet restore ./test/HealthChecks.SqlServer.Tests/HealthChecks.SqlServer.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.SqlServer/HealthChecks.SqlServer.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.SqlServer.Tests/HealthChecks.SqlServer.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.SqlServer/HealthChecks.SqlServer.csproj &&
dotnet build --no-restore ./test/HealthChecks.SqlServer.Tests/HealthChecks.SqlServer.Tests.csproj
- name: Test
run: >
dotnet test
./test/HealthChecks.SqlServer.Tests/HealthChecks.SqlServer.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: SqlServer
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.SqlServer/HealthChecks.SqlServer.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.SqlServer.Tests/HealthChecks.SqlServer.Tests.csproj
CODECOV_FLAGS: SqlServer
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.PostgreSql" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.MsSql" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Redis" Version="$(TestcontainersVersion)" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace HealthChecks.SqlServer.Tests.Functional;

public class sqlserver_healthcheck_should
public class sqlserver_healthcheck_should(SqlServerContainerFixture sqlServerContainerFixture) : IClassFixture<SqlServerContainerFixture>
{
[Fact]
public async Task be_healthy_if_sqlServer_is_available()
{
var connectionString = "Server=tcp:localhost,5433;Initial Catalog=master;User Id=sa;Password=Password12!;Encrypt=false";
var connectionString = sqlServerContainerFixture.GetConnectionString();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
Expand Down Expand Up @@ -57,7 +57,7 @@ public async Task be_unhealthy_if_sqlServer_is_not_available()
[Fact]
public async Task be_unhealthy_if_sqlquery_spec_is_not_valid()
{
var connectionString = "Server=tcp:localhost,5433;Initial Catalog=master;User Id=sa;Password=Password12!;Encrypt=false";
var connectionString = sqlServerContainerFixture.GetConnectionString();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<ProjectReference Include="..\..\src\HealthChecks.SqlServer\HealthChecks.SqlServer.csproj" />
</ItemGroup>
Expand Down
35 changes: 35 additions & 0 deletions test/HealthChecks.SqlServer.Tests/SqlServerContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Testcontainers.MsSql;

namespace HealthChecks.SqlServer.Tests;

public sealed class SqlServerContainerFixture : IAsyncLifetime
{
public const string Registry = "mcr.microsoft.com";

public const string Image = "mssql/server";

public const string Tag = "2022-latest";

public MsSqlContainer? Container { get; private set; }

public string GetConnectionString() => Container?.GetConnectionString() ??
throw new InvalidOperationException("The test container was not initialized.");

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

public async Task DisposeAsync()
{
if (Container is not null)
await Container.DisposeAsync();
}

public static async Task<MsSqlContainer> CreateContainerAsync()
{
var container = new MsSqlBuilder()
.WithImage($"{Registry}/{Image}:{Tag}")
.Build();
await container.StartAsync();

return container;
}
}

0 comments on commit feb1fee

Please sign in to comment.