Skip to content

Commit

Permalink
Use ContainerFixture for AzuriteContainerTest
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Nov 23, 2024
1 parent a897816 commit a404df6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
56 changes: 19 additions & 37 deletions tests/Testcontainers.Azurite.Tests/AzuriteContainerTest.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,8 @@
namespace Testcontainers.Azurite;

public abstract class AzuriteContainerTest : IAsyncLifetime
public abstract class AzuriteContainerTest(AzuriteContainerTest.AzuriteFixture fixture)
{
private readonly AzuriteContainer _azuriteContainer;

private AzuriteContainerTest(AzuriteContainer azuriteContainer)
{
_azuriteContainer = azuriteContainer;
}

public Task InitializeAsync()
{
return _azuriteContainer.StartAsync();
}

public Task DisposeAsync()
{
return _azuriteContainer.DisposeAsync().AsTask();
}
private readonly AzuriteContainer _azuriteContainer = fixture.Container;

[Fact]
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))]
Expand Down Expand Up @@ -72,48 +57,45 @@ private static bool HasError<TResponseEntity>(NullableResponse<TResponseEntity>
}
}

public class AzuriteFixture(IMessageSink messageSink) : ContainerFixture<AzuriteBuilder, AzuriteContainer>(messageSink);

[UsedImplicitly]
public sealed class AzuriteDefaultConfiguration : AzuriteContainerTest
public sealed class AzuriteInMemoryFixture(IMessageSink messageSink) : AzuriteFixture(messageSink)
{
public AzuriteDefaultConfiguration()
: base(new AzuriteBuilder().Build())
{
}
protected override AzuriteBuilder Configure(AzuriteBuilder builder) => builder.WithInMemoryPersistence();
}

[UsedImplicitly]
public sealed class AzuriteInMemoryConfiguration : AzuriteContainerTest
public sealed class AzuriteMemoryLimitFixture(IMessageSink messageSink) : AzuriteFixture(messageSink)
{
public AzuriteInMemoryConfiguration()
: base(new AzuriteBuilder().WithInMemoryPersistence().Build())
{
}
public const int MemoryLimitInMb = 64;

protected override AzuriteBuilder Configure(AzuriteBuilder builder) => builder.WithInMemoryPersistence(MemoryLimitInMb);
}

[UsedImplicitly]
public sealed class AzuriteMemoryLimitConfiguration : AzuriteContainerTest
{
private const int MemoryLimitInMb = 64;
public sealed class AzuriteDefaultConfiguration(AzuriteFixture fixture) : AzuriteContainerTest(fixture), IClassFixture<AzuriteFixture>;

private static readonly string[] LineEndings = { "\r\n", "\n" };
[UsedImplicitly]
public sealed class AzuriteInMemoryConfiguration(AzuriteInMemoryFixture fixture) : AzuriteContainerTest(fixture), IClassFixture<AzuriteInMemoryFixture>;

public AzuriteMemoryLimitConfiguration()
: base(new AzuriteBuilder().WithInMemoryPersistence(MemoryLimitInMb).Build())
{
}
[UsedImplicitly]
public sealed class AzuriteMemoryLimitConfiguration(AzuriteMemoryLimitFixture fixture) : AzuriteContainerTest(fixture), IClassFixture<AzuriteMemoryLimitFixture>
{
private static readonly string[] LineEndings = { "\r\n", "\n" };

[Fact]
public async Task MemoryLimitIsConfigured()
{
// Given
var (stdout, _) = await _azuriteContainer.GetLogsAsync(timestampsEnabled: false)
var (stdout, _) = await fixture.Container.GetLogsAsync(timestampsEnabled: false)
.ConfigureAwait(true);

// When
var firstLine = stdout.Split(LineEndings, StringSplitOptions.RemoveEmptyEntries).First();

// Then
Assert.StartsWith(string.Format(CultureInfo.InvariantCulture, "In-memory extent storage is enabled with a limit of {0:F2} MB", MemoryLimitInMb), firstLine);
Assert.StartsWith(string.Format(CultureInfo.InvariantCulture, "In-memory extent storage is enabled with a limit of {0:F2} MB", AzuriteMemoryLimitFixture.MemoryLimitInMb), firstLine);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="../../src/Testcontainers.Azurite/Testcontainers.Azurite.csproj"/>
<ProjectReference Include="../../src/Testcontainers.Xunit/Testcontainers.Xunit.csproj" />
<ProjectReference Include="../Testcontainers.Commons/Testcontainers.Commons.csproj"/>
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion tests/Testcontainers.Azurite.Tests/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
global using Azure.Storage.Queues;
global using DotNet.Testcontainers.Commons;
global using JetBrains.Annotations;
global using Xunit;
global using Testcontainers.Xunit;
global using Xunit;
global using Xunit.Abstractions;

0 comments on commit a404df6

Please sign in to comment.