-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Redis tests to Testcontainers (#2345)
* Migrate Redis tests to Testcontainers * Address PR feedback
- Loading branch information
Showing
6 changed files
with
53 additions
and
10 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
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.Redis.Tests/HealthChecks.Redis.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,35 @@ | ||
using Testcontainers.Redis; | ||
|
||
namespace HealthChecks.Redis.Tests; | ||
|
||
public sealed class RedisContainerFixture : IAsyncLifetime | ||
{ | ||
public const string Registry = "docker.io"; | ||
|
||
public const string Image = "library/redis"; | ||
|
||
public const string Tag = "7.4"; | ||
|
||
public RedisContainer? 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<RedisContainer> CreateContainerAsync() | ||
{ | ||
var container = new RedisBuilder() | ||
.WithImage($"{Registry}/{Image}:{Tag}") | ||
.Build(); | ||
await container.StartAsync(); | ||
|
||
return container; | ||
} | ||
} |