-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate HealthChecks.MySql tests to Testcontainers (#2353)
- Loading branch information
Showing
5 changed files
with
48 additions
and
47 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
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.MySql; | ||
|
||
namespace HealthChecks.MySql.Tests; | ||
|
||
public sealed class MySqlContainerFixture : IAsyncLifetime | ||
{ | ||
public const string Registry = "docker.io"; | ||
|
||
public const string Image = "library/mysql"; | ||
|
||
public const string Tag = "9.1"; | ||
|
||
public MySqlContainer? 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<MySqlContainer> CreateContainerAsync() | ||
{ | ||
var container = new MySqlBuilder() | ||
.WithImage($"{Registry}/{Image}:{Tag}") | ||
.Build(); | ||
await container.StartAsync(); | ||
|
||
return container; | ||
} | ||
} |