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_gremlin_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:
gremlin:
image: tinkerpop/gremlin-server
ports:
- 8182:8182
env:
VIRTUAL_HOST: gremlin.docker
VIRTUAL_PORT: 8182
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.Gremlin/HealthChecks.Gremlin.csproj &&
dotnet restore ./test/HealthChecks.Gremlin.Tests/HealthChecks.Gremlin.Tests.csproj
- name: Check formatting
run: |
dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.Gremlin/HealthChecks.Gremlin.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.Gremlin.Tests/HealthChecks.Gremlin.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
- name: Build
run: |
dotnet build --no-restore ./src/HealthChecks.Gremlin/HealthChecks.Gremlin.csproj &&
dotnet build --no-restore ./test/HealthChecks.Gremlin.Tests/HealthChecks.Gremlin.Tests.csproj
- name: Test
run: >
dotnet test
./test/HealthChecks.Gremlin.Tests/HealthChecks.Gremlin.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: Gremlin
directory: .coverage
uses: ./.github/workflows/reusable_ci_workflow.yml
with:
PROJECT_PATH: ./src/HealthChecks.Gremlin/HealthChecks.Gremlin.csproj
TEST_PROJECT_PATH: ./test/HealthChecks.Gremlin.Tests/HealthChecks.Gremlin.Tests.csproj
CODECOV_FLAGS: Gremlin
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

namespace HealthChecks.Gremlin.Tests.Functional;

public class gremlin_healthcheck_should
public class gremlin_healthcheck_should(GremlinContainerFixture gremlinFixture) : IClassFixture<GremlinContainerFixture>
{
[Fact]
public async Task be_healthy_if_gremlin_is_available()
{
var options = gremlinFixture.GetConnectionOptions();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddGremlin(_ => new GremlinOptions
{
Hostname = "localhost",
Port = 8182,
EnableSsl = false
}, tags: ["gremlin"]);
.AddGremlin(_ => options, tags: ["gremlin"]);
})
.Configure(app =>
{
Expand All @@ -36,22 +33,14 @@ public async Task be_healthy_if_gremlin_is_available()
[Fact]
public async Task be_healthy_if_multiple_gremlin_are_available()
{
var options = gremlinFixture.GetConnectionOptions();

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddGremlin(_ => new GremlinOptions
{
Hostname = "localhost",
Port = 8182,
EnableSsl = false
}, tags: ["gremlin"], name: "1")
.AddGremlin(_ => new GremlinOptions
{
Hostname = "localhost",
Port = 8182,
EnableSsl = false
}, tags: ["gremlin"], name: "2");
.AddGremlin(_ => options, tags: ["gremlin"], name: "1")
.AddGremlin(_ => options, tags: ["gremlin"], name: "2");
})
.Configure(app =>
{
Expand All @@ -71,16 +60,15 @@ public async Task be_healthy_if_multiple_gremlin_are_available()
[Fact]
public async Task be_unhealthy_if_gremlin_is_not_available()
{
var options = gremlinFixture.GetConnectionOptions();

options.Hostname = "wronghost";

var webHostBuilder = new WebHostBuilder()
.ConfigureServices(services =>
{
services.AddHealthChecks()
.AddGremlin(_ => new GremlinOptions
{
Hostname = "wronghost",
Port = 8182,
EnableSsl = false
}, tags: ["gremlin"]);
.AddGremlin(_ => options, tags: ["gremlin"]);
})
.Configure(app =>
{
Expand Down
55 changes: 55 additions & 0 deletions test/HealthChecks.Gremlin.Tests/GremlinContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using DotNet.Testcontainers.Builders;
using DotNet.Testcontainers.Containers;

namespace HealthChecks.Gremlin.Tests;

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

private const string Image = "tinkerpop/gremlin-server";

private const string Tag = "3.7.4";

private const int Port = 8182;

public IContainer? Container { get; private set; }

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

var options = new GremlinOptions
{
Hostname = Container.Hostname,
Port = Container.GetMappedPublicPort(Port),
EnableSsl = false
};

return options;
}

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

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

private static async Task<IContainer> CreateContainerAsync()
{
var waitStrategy = Wait
.ForUnixContainer()
.UntilPortIsAvailable(Port);

var container = new ContainerBuilder()
.WithImage($"{Registry}/{Image}:{Tag}")
.WithPortBinding(Port, true)
.WithWaitStrategy(waitStrategy)
.Build();

await container.StartAsync();

return container;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<ProjectReference Include="..\..\src\HealthChecks.Gremlin\HealthChecks.Gremlin.csproj" />
</ItemGroup>

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

</Project>
Loading