mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-11-02 22:33:58 +01:00
MinioFixture starts a MinIO-compatible server in Docker with Testcontainers (Silo, since MinIO no longer publishes images) and points S3Clients at it. S3ServiceTests cover signed uploads and object sizes, deleting an object and a user's directory, and multipart uploads within and past the storage limit. The interface stub moves out of ApiErrorResponseTests so both can use it. Running the tests now needs Docker.
39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
using Amazon.S3;
|
|
using Testcontainers.Minio;
|
|
|
|
namespace Notesnook.API.Tests;
|
|
|
|
/// <summary>
|
|
/// A throwaway MinIO-compatible S3 server in Docker, with S3Clients configured to use it.
|
|
/// </summary>
|
|
public sealed class MinioFixture : IAsyncLifetime
|
|
{
|
|
// StorageQuotaTests sets the same bucket name, so the two never disagree
|
|
public const string Bucket = "test";
|
|
|
|
// MinIO no longer publishes images; Silo is an API-compatible fork that does
|
|
private readonly MinioContainer container = new MinioBuilder("pgsty/silo:RELEASE.2026-09-16T00-00-00Z").Build();
|
|
|
|
public async Task InitializeAsync()
|
|
{
|
|
await container.StartAsync();
|
|
|
|
// S3Clients reads these when it's created; only S3ServiceTests uses this fixture
|
|
Environment.SetEnvironmentVariable("S3_SERVICE_URL", container.GetConnectionString());
|
|
Environment.SetEnvironmentVariable("S3_REGION", "us-east-1");
|
|
Environment.SetEnvironmentVariable("S3_ACCESS_KEY_ID", container.GetAccessKey());
|
|
Environment.SetEnvironmentVariable("S3_ACCESS_KEY", container.GetSecretKey());
|
|
Environment.SetEnvironmentVariable("S3_BUCKET_NAME", Bucket);
|
|
|
|
using var client = new AmazonS3Client(container.GetAccessKey(), container.GetSecretKey(), new AmazonS3Config
|
|
{
|
|
ServiceURL = container.GetConnectionString(),
|
|
AuthenticationRegion = "us-east-1",
|
|
ForcePathStyle = true
|
|
});
|
|
await client.PutBucketAsync(Bucket);
|
|
}
|
|
|
|
public Task DisposeAsync() => container.DisposeAsync().AsTask();
|
|
}
|