Skip to content

Commit 9b66043

Browse files
committed
Try to fix tests
1 parent 53ca865 commit 9b66043

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

src/Storage.Tests/Storage.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
</PackageReference>
20-
<PackageReference Include="Testcontainers.Minio" Version="3.8.0" />
20+
<PackageReference Include="Testcontainers" Version="3.8.0" />
2121
<PackageReference Include="xunit" Version="2.7.1" />
2222
<PackageReference Include="JunitXml.TestLogger" Version="3.1.12" />
2323
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8">

src/Storage.Tests/Utils/StorageFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using AutoFixture;
2-
using Testcontainers.Minio;
2+
using DotNet.Testcontainers.Containers;
33

44
namespace Storage.Tests.Utils;
55

@@ -9,7 +9,7 @@ public sealed class StorageFixture : IDisposable, IAsyncDisposable
99

1010
private const int DefaultByteArraySize = 1 * 1024 * 1024; // 7Mb
1111

12-
private readonly MinioContainer? _container;
12+
private readonly IContainer? _container;
1313
private Fixture? _fixture;
1414

1515
public StorageFixture()
Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
using System.Globalization;
2-
using Testcontainers.Minio;
2+
using DotNet.Testcontainers.Builders;
3+
using DotNet.Testcontainers.Containers;
34

45
namespace Storage.Tests.Utils;
56

67
public 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

Comments
 (0)