File tree Expand file tree Collapse file tree
test/HealthChecks.MySql.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626 - Directory.Build.props
2727 - Directory.Build.targets
2828 - Directory.Packages.props
29-
3029jobs :
3130 build :
32- runs-on : ubuntu-latest
33- services :
34- mysql :
35- image : mysql
36- ports :
37- - 3306:3306
38- env :
39- MYSQL_ROOT_PASSWORD : Password12!
40- steps :
41- - uses : actions/checkout@v3
42- - name : Setup .NET
43- uses : actions/setup-dotnet@v4
44- with :
45- dotnet-version : |
46- 8.0.x
47- 9.0.x
48- - name : Restore
49- run : |
50- dotnet restore ./src/HealthChecks.MySql/HealthChecks.MySql.csproj &&
51- dotnet restore ./test/HealthChecks.MySql.Tests/HealthChecks.MySql.Tests.csproj
52- - name : Check formatting
53- run : |
54- dotnet format --no-restore --verify-no-changes --severity warn ./src/HealthChecks.MySql/HealthChecks.MySql.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1) &&
55- dotnet format --no-restore --verify-no-changes --severity warn ./test/HealthChecks.MySql.Tests/HealthChecks.MySql.Tests.csproj || (echo "Run 'dotnet format' to fix issues" && exit 1)
56- - name : Build
57- run : |
58- dotnet build --no-restore ./src/HealthChecks.MySql/HealthChecks.MySql.csproj &&
59- dotnet build --no-restore ./test/HealthChecks.MySql.Tests/HealthChecks.MySql.Tests.csproj
60- - name : Test
61- run : >
62- dotnet test
63- ./test/HealthChecks.MySql.Tests/HealthChecks.MySql.Tests.csproj
64- --no-restore
65- --no-build
66- --collect "XPlat Code Coverage"
67- --results-directory .coverage
68- --
69- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover
70- - name : Upload Coverage
71- uses : codecov/codecov-action@v5
72- with :
73- flags : MySql
74- directory : .coverage
31+ uses : ./.github/workflows/reusable_ci_workflow.yml
32+ with :
33+ PROJECT_PATH : ./src/HealthChecks.MySql/HealthChecks.MySql.csproj
34+ TEST_PROJECT_PATH : ./test/HealthChecks.MySql.Tests/HealthChecks.MySql.Tests.csproj
35+ CODECOV_FLAGS : MySql
Original file line number Diff line number Diff line change 105105 <PackageVersion Include =" Testcontainers.PostgreSql" Version =" $(TestcontainersVersion)" />
106106 <PackageVersion Include =" TestContainers.MongoDb" Version =" $(TestcontainersVersion)" />
107107 <PackageVersion Include =" Testcontainers.MsSql" Version =" $(TestcontainersVersion)" />
108+ <PackageVersion Include =" Testcontainers.MySql" Version =" $(TestcontainersVersion)" />
108109 <PackageVersion Include =" Testcontainers.Redis" Version =" $(TestcontainersVersion)" />
109110 <PackageVersion Include =" Testcontainers.RabbitMq" Version =" $(TestcontainersVersion)" />
110111 <PackageVersion Include =" xunit" Version =" 2.9.2" />
Original file line number Diff line number Diff line change 33
44namespace HealthChecks . MySql . Tests . Functional ;
55
6- public class mysql_healthcheck_should
6+ public class mysql_healthcheck_should ( MySqlContainerFixture mySqlContainerFixture ) : IClassFixture < MySqlContainerFixture >
77{
88 [ Fact ]
99 public async Task be_healthy_when_mysql_server_is_available_using_data_source ( )
1010 {
11- var connectionString = "server=localhost;port=3306;database=information_schema;uid=root;password=Password12!" ;
11+ var connectionString = mySqlContainerFixture . GetConnectionString ( ) ;
1212
1313 var webHostBuilder = new WebHostBuilder ( )
1414 . ConfigureServices ( services =>
@@ -35,7 +35,7 @@ public async Task be_healthy_when_mysql_server_is_available_using_data_source()
3535 [ Fact ]
3636 public async Task be_healthy_when_mysql_server_is_available_using_connection_string ( )
3737 {
38- var connectionString = "server=localhost;port=3306;database=information_schema;uid=root;password=Password12!" ;
38+ var connectionString = mySqlContainerFixture . GetConnectionString ( ) ;
3939
4040 var webHostBuilder = new WebHostBuilder ( )
4141 . ConfigureServices ( services =>
Original file line number Diff line number Diff line change 88 <ProjectReference Include =" ..\..\src\HealthChecks.MySql\HealthChecks.MySql.csproj" />
99 </ItemGroup >
1010
11+ <ItemGroup >
12+ <PackageReference Include =" Testcontainers.MySql" />
13+ </ItemGroup >
14+
1115</Project >
Original file line number Diff line number Diff line change 1+ using Testcontainers . MySql ;
2+
3+ namespace HealthChecks . MySql . Tests ;
4+
5+ public sealed class MySqlContainerFixture : IAsyncLifetime
6+ {
7+ public const string Registry = "docker.io" ;
8+
9+ public const string Image = "library/mysql" ;
10+
11+ public const string Tag = "9.1" ;
12+
13+ public MySqlContainer ? Container { get ; private set ; }
14+
15+ public string GetConnectionString ( ) => Container ? . GetConnectionString ( ) ??
16+ throw new InvalidOperationException ( "The test container was not initialized." ) ;
17+
18+ public async Task InitializeAsync ( ) => Container = await CreateContainerAsync ( ) ;
19+
20+ public async Task DisposeAsync ( )
21+ {
22+ if ( Container is not null )
23+ await Container . DisposeAsync ( ) ;
24+ }
25+
26+ public static async Task < MySqlContainer > CreateContainerAsync ( )
27+ {
28+ var container = new MySqlBuilder ( )
29+ . WithImage ( $ "{ Registry } /{ Image } :{ Tag } ")
30+ . Build ( ) ;
31+ await container . StartAsync ( ) ;
32+
33+ return container ;
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments