11using System . Globalization ;
2- using Testcontainers . Minio ;
2+ using DotNet . Testcontainers . Builders ;
3+ using DotNet . Testcontainers . Containers ;
34
45namespace Storage . Tests . Utils ;
56
67public static class TestHelper
78{
9+ public const int MinioInternalPort = 9000 ;
810 public const string SecretKey = "ChangeMe123" ;
911 public const string Username = "ROOTUSER" ;
1012
11- public static S3Settings CreateSettings ( MinioContainer ? container = null )
13+ public static S3Settings CreateSettings ( IContainer ? container = null )
1214 {
1315 var environmentPort = Environment . GetEnvironmentVariable ( "STORAGE_PORT" ) ;
1416 int ? port = string . IsNullOrEmpty ( environmentPort )
15- ? container ? . GetMappedPublicPort ( MinioBuilder . MinioPort ) ?? 5300
17+ ? container ? . GetMappedPublicPort ( MinioInternalPort ) ?? 5300
1618 : environmentPort is "null"
1719 ? null
1820 : int . Parse ( environmentPort , CultureInfo . InvariantCulture ) ;
@@ -31,33 +33,47 @@ public static S3Settings CreateSettings(MinioContainer? container = null)
3133 } ;
3234 }
3335
34- public static MinioContainer CreateContainer ( bool run = true )
36+ public static IContainer CreateContainer ( bool run = true )
3537 {
36- var container = new MinioBuilder ( )
37- . WithPassword ( SecretKey )
38- . WithUsername ( Username )
38+ var container = new ContainerBuilder ( )
39+ . WithImage ( "minio/minio:latest" )
40+ . WithEnvironment ( "MINIO_ROOT_USER" , Username )
41+ . WithEnvironment ( "MINIO_ROOT_PASSWORD" , SecretKey )
42+ . WithPortBinding ( MinioInternalPort , true )
43+ . WithCommand ( "server" , "/data" )
44+ . WithWaitStrategy ( Wait
45+ . ForUnixContainer ( )
46+ . UntilHttpRequestIsSucceeded ( static request =>
47+ request . ForPath ( "/minio/health/ready" ) . ForPort ( MinioInternalPort ) ) )
3948 . Build ( ) ;
4049
4150 if ( run )
4251 {
43- container . StartAsync ( ) . Wait ( ) ;
52+ container
53+ . StartAsync ( )
54+ . ConfigureAwait ( false )
55+ . GetAwaiter ( )
56+ . GetResult ( ) ;
4457 }
4558
4659 return container ;
4760 }
4861
4962 public static void EnsureBucketExists ( S3Client client )
5063 {
51- EnsureBucketExists ( client , CancellationToken . None ) . Wait ( ) ;
64+ EnsureBucketExists ( client , CancellationToken . None )
65+ . ConfigureAwait ( false )
66+ . GetAwaiter ( )
67+ . GetResult ( ) ;
5268 }
5369
5470 public static async Task EnsureBucketExists ( S3Client client , CancellationToken cancellation )
5571 {
56- if ( await client . IsBucketExists ( cancellation ) )
72+ if ( await client . IsBucketExists ( cancellation ) . ConfigureAwait ( false ) )
5773 {
5874 return ;
5975 }
6076
61- await client . CreateBucket ( cancellation ) ;
77+ await client . CreateBucket ( cancellation ) . ConfigureAwait ( false ) ;
6278 }
6379}
0 commit comments