-
Notifications
You must be signed in to change notification settings - Fork 808
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate HealthChecks.Qdrant tests to Testcontainers
- Loading branch information
Showing
5 changed files
with
64 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
test/HealthChecks.Qdrant.Tests/HealthChecks.Qdrant.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using DotNet.Testcontainers.Builders; | ||
using DotNet.Testcontainers.Containers; | ||
|
||
namespace HealthChecks.Qdrant.Tests; | ||
|
||
public sealed class QdrantContainerFixture : IAsyncLifetime | ||
{ | ||
public const string Registry = "docker.io"; | ||
|
||
public const string Image = "qdrant/qdrant"; | ||
|
||
public const string Tag = "v1.12.1"; | ||
|
||
private const int GrpcPort = 6334; | ||
|
||
public IContainer? Container { get; private set; } | ||
|
||
public string GetConnectionString() | ||
{ | ||
if (Container is null) | ||
{ | ||
throw new InvalidOperationException("The test container was not initialized."); | ||
} | ||
string endpoint = new UriBuilder("http", Container.Hostname, Container.GetMappedPublicPort(GrpcPort)).ToString(); | ||
return endpoint; | ||
} | ||
|
||
public async Task InitializeAsync() => Container = await CreateContainerAsync(); | ||
|
||
public async Task DisposeAsync() | ||
{ | ||
if (Container is not null) | ||
await Container.DisposeAsync(); | ||
} | ||
|
||
public static async Task<IContainer> CreateContainerAsync() | ||
{ | ||
var container = new ContainerBuilder() | ||
.WithImage($"{Registry}/{Image}:{Tag}") | ||
.WithPortBinding(GrpcPort, true) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(GrpcPort)) | ||
.Build(); | ||
await container.StartAsync(); | ||
|
||
return container; | ||
} | ||
} |