Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 5 additions & 43 deletions .github/workflows/healthchecks_ravendb_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,8 @@ on:

jobs:
build:
runs-on: ubuntu-latest
services:
ravendb:
image: ravendb/ravendb
ports:
- 9030:8080
env:
RAVEN_ARGS: --Setup.Mode=None
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.RavenDB/HealthChecks.RavenDB.csproj &&
dotnet restore ./test/HealthChecks.RavenDb.Tests/HealthChecks.RavenDb.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.RavenDb.Tests/HealthChecks.RavenDb.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj &&
dotnet build --no-restore ./test/HealthChecks.RavenDb.Tests/HealthChecks.RavenDb.Tests.csproj
- name: Test
run: >
dotnet test
./test/HealthChecks.RavenDb.Tests/HealthChecks.RavenDb.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: RavenDb
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.RavenDB/HealthChecks.RavenDB.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.RavenDb.Tests/HealthChecks.RavenDb.Tests.csproj
CODECOV_FLAGS: RavenDb
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<PackageVersion Include="TestContainers.MongoDb" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.MsSql" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.MySql" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.RavenDb" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.Redis" Version="$(TestcontainersVersion)" />
<PackageVersion Include="Testcontainers.RabbitMq" Version="$(TestcontainersVersion)" />
<PackageVersion Include="xunit" Version="2.9.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

namespace HealthChecks.RavenDb.Tests.Functional;

public class ravendb_healthcheck_should
public class ravendb_healthcheck_should : IClassFixture<RavenDbContainerFixture>
{
private readonly string[] _urls = ["http://localhost:9030"];
private readonly string[] _urls;

public ravendb_healthcheck_should()
public ravendb_healthcheck_should(RavenDbContainerFixture ravenDbFixture)
{
_urls = [ravenDbFixture.GetConnectionString()];

try
{
using var store = new DocumentStore
Expand All @@ -23,7 +25,10 @@ public ravendb_healthcheck_should()

store.Maintenance.Server.Send(new CreateDatabaseOperation(new DatabaseRecord("Demo")));
}
catch { }
catch
{
// ignored
}
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,28 @@

namespace HealthChecks.RavenDb.Tests.Functional;

public class ravendb_healthcheck_should_single_connection_string
public class ravendb_healthcheck_should_single_connection_string : IClassFixture<RavenDbContainerFixture>
{
private const string ConnectionString = "http://localhost:9030";
private readonly string _connectionString;

public ravendb_healthcheck_should_single_connection_string()
public ravendb_healthcheck_should_single_connection_string(RavenDbContainerFixture ravenDbFixture)
{
_connectionString = ravenDbFixture.GetConnectionString();

try
{
using var store = new DocumentStore
{
Urls = [ConnectionString],
};
using var store = new DocumentStore();

store.Urls = [_connectionString];

store.Initialize();

store.Maintenance.Server.Send(new CreateDatabaseOperation(new DatabaseRecord("Demo")));
}
catch { }
catch
{
// ignored
}
}

[Fact]
Expand All @@ -33,7 +37,7 @@ public async Task be_healthy_if_ravendb_is_available()
{
services
.AddHealthChecks()
.AddRavenDB(setup => setup.Urls = [ConnectionString], tags: ["ravendb"]);
.AddRavenDB(setup => setup.Urls = [_connectionString], tags: ["ravendb"]);
})
.Configure(app =>
{
Expand All @@ -58,7 +62,7 @@ public async Task be_healthy_if_ravendb_is_available_and_contains_specific_datab
{
services
.AddHealthChecks()
.AddRavenDB(setup => setup.Urls = [ConnectionString], "Demo", tags: ["ravendb"]);
.AddRavenDB(setup => setup.Urls = [_connectionString], "Demo", tags: ["ravendb"]);
})
.Configure(app =>
{
Expand Down Expand Up @@ -112,7 +116,7 @@ public async Task be_unhealthy_if_ravendb_is_available_but_database_doesnot_exis
.AddHealthChecks()
.AddRavenDB(setup =>
{
setup.Urls = [ConnectionString];
setup.Urls = [_connectionString];
setup.Database = "ThisDatabaseReallyDoesnExist";
}, "ThisDatabaseReallyDoesnExist", tags: ["ravendb"]);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<ProjectReference Include="..\..\src\HealthChecks.RavenDB\HealthChecks.RavenDB.csproj" />
</ItemGroup>

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

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

namespace HealthChecks.RavenDb.Tests;

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

private const string Image = "ravendb/ravendb";

private const string Tag = "7.1-latest";

public RavenDbContainer? 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<RavenDbContainer?> CreateContainerAsync()
{
var container = new RavenDbBuilder()
.WithImage($"{Registry}/{Image}:{Tag}")
.Build();

await container.StartAsync();

return container;
}
}
Loading