File tree Expand file tree Collapse file tree 3 files changed +51
-2
lines changed
Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 1+ using Microsoft . Extensions . Configuration ;
12using Projects ;
23
34var builder = DistributedApplication . CreateBuilder ( args ) ;
45
5- var mailPit = builder . AddMailPit ( "mailpit" ) ;
6+ var httpPort = builder . Configuration . GetValue < int ? > ( "MailPit:HttpPort" ) ;
7+ var mailPit = builder . AddMailPit ( "mailpit" , httpPort : httpPort ) ;
68
79var sendmail = builder . AddProject < CommunityToolkit_Aspire_Hosting_MailPit_SendMailApi > ( "sendmail" )
810 . WithReference ( mailPit )
Original file line number Diff line number Diff line change @@ -37,7 +37,14 @@ public static IResourceBuilder<MailPitContainerResource> AddMailPit(this IDistri
3737 targetPort : MailPitContainerResource . HttpEndpointPort ,
3838 port : httpPort ,
3939 name : MailPitContainerResource . HttpEndpointName )
40- . WithHttpHealthCheck ( "/" , httpPort , MailPitContainerResource . HttpEndpointName ) ;
40+ . WithHttpHealthCheck (
41+ path : "/livez" ,
42+ statusCode : 200 ,
43+ endpointName : MailPitContainerResource . HttpEndpointName )
44+ . WithHttpHealthCheck (
45+ path : "/readyz" ,
46+ statusCode : 200 ,
47+ endpointName : MailPitContainerResource . HttpEndpointName ) ;
4148
4249 return rb ;
4350 }
Original file line number Diff line number Diff line change 1+ using Aspire . Components . Common . Tests ;
2+ using Aspire . Hosting ;
3+ using CommunityToolkit . Aspire . Testing ;
4+ using Microsoft . Extensions . Configuration ;
5+ using Microsoft . Extensions . Hosting ;
6+ using System . Security . Cryptography ;
7+
8+ namespace CommunityToolkit . Aspire . Hosting . MailPit . Tests ;
9+
10+ [ RequiresDocker ]
11+ public sealed class AppHostHealthChecksTests ( AppHostHealthChecksTests . MailPitAspireIntegrationTestFixture < Projects . CommunityToolkit_Aspire_Hosting_MailPit_AppHost > fixture )
12+ : IClassFixture < AppHostHealthChecksTests . MailPitAspireIntegrationTestFixture < Projects . CommunityToolkit_Aspire_Hosting_MailPit_AppHost > >
13+ {
14+ private const string ResourceName = "mailpit" ;
15+
16+ [ Fact ]
17+ public async Task ResourceStartsHealthyUsingCustomHttpPort ( )
18+ {
19+ await fixture . ResourceNotificationService
20+ . WaitForResourceHealthyAsync ( ResourceName )
21+ . WaitAsync ( TimeSpan . FromMinutes ( 1 ) ) ;
22+ }
23+
24+ public sealed class MailPitAspireIntegrationTestFixture < TEntryPoint > ( )
25+ : AspireIntegrationTestFixture < TEntryPoint > where TEntryPoint : class
26+ {
27+ protected override void OnBuilderCreated ( DistributedApplicationBuilder applicationBuilder )
28+ {
29+ base . OnBuilderCreated ( applicationBuilder ) ;
30+ applicationBuilder . Configuration . AddInMemoryCollection ( [
31+ new KeyValuePair < string , string ? > ( "MailPit:HttpPort" , $ "{ GetRandomPort ( ) } ") ,
32+ ] ) ;
33+ }
34+
35+ private static int GetRandomPort ( )
36+ {
37+ return RandomNumberGenerator . GetInt32 ( 1024 , 65535 ) ;
38+ }
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments