Path: redb-route/tests/redb.Route.Tests.S3/S3ConnectionConfigTests.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.S3/S3ConnectionConfigTests.cs
----
using Amazon.Runtime;
using redb.Route.Core;
using redb.Route.S3;
namespace redb.Route.Tests.S3;
///
/// Connection options that were
/// declared, documented and bound — but never reached the AWS SDK config.
///
public sealed class S3ConnectionConfigTests
{
[Fact]
public void Factory_SocketTimeout_ReachesSdkConfig()
{
var client = new S3ConnectionFactory
{
ServiceUrl = "http://localhost:9000",
AccessKey = "k",
SecretKey = "s",
SocketTimeout = 12_345,
}.Build();
client.Config.Timeout.Should().Be(TimeSpan.FromMilliseconds(12_345),
"SocketTimeout must reach the SDK as the request timeout, not be a dead option");
}
[Fact]
public void Factory_ConnectionTimeout_MapsToConnectTimeout()
{
var client = new S3ConnectionFactory
{
ServiceUrl = "http://localhost:9000",
AccessKey = "k",
SecretKey = "s",
ConnectionTimeout = 7_000,
}.Build();
client.Config.ConnectTimeout.Should().Be(TimeSpan.FromMilliseconds(7_000));
}
[Fact]
public void Factory_RetryModeAdaptive_ReachesSdkConfig()
{
var client = new S3ConnectionFactory
{
ServiceUrl = "http://localhost:9000",
AccessKey = "k",
SecretKey = "s",
RetryMode = "adaptive",
}.Build();
client.Config.RetryMode.Should().Be(RequestRetryMode.Adaptive,
"RetryMode must reach the SDK, not be a dead option");
}
[Fact]
public void Factory_TrustAllCertificates_InstallsHttpClientFactory()
{
var client = new S3ConnectionFactory
{
ServiceUrl = "https://localhost:9000",
AccessKey = "k",
SecretKey = "s",
TrustAllCertificates = true,
}.Build();
client.Config.HttpClientFactory.Should().NotBeNull(
"TrustAllCertificates must set a factory with certificate validation turned off");
}
[Fact]
public async Task ConnectionFactoryTypo_FailsLoud_NeverFallsBackToUriParams()
{
// A typo in connectionFactory used to connect silently
// with the URI credentials — a working configuration and a misconfiguration looked the same.
await using var ctx = new RouteContext();
var component = new S3Component();
ctx.AddComponent(component);
var endpoint = (S3Endpoint)ctx.GetEndpoint(
"s3://bucket?connectionFactory=typo-name&serviceUrl=http://localhost:9000" +
"&accessKey=k&secretKey=s");
var act = () => endpoint.GetOrCreateClientAsync();
await act.Should().ThrowAsync()
.Where(e => e.Message.Contains("typo-name"),
"a factory name that is set but not found must fail loudly");
}
[Fact]
public async Task EndpointOptions_Trio_ReachesSdkConfig()
{
var uri = EndpointUriParser.Parse(
"s3://bucket?serviceUrl=http://localhost:9000&accessKey=k&secretKey=s" +
"&socketTimeout=23456&retryMode=adaptive&trustAllCertificates=true");
var endpoint = (S3Endpoint)new S3Component().CreateEndpoint(uri);
var client = await endpoint.GetOrCreateClientAsync();
client.Config.Timeout.Should().Be(TimeSpan.FromMilliseconds(23_456));
client.Config.RetryMode.Should().Be(RequestRetryMode.Adaptive);
client.Config.HttpClientFactory.Should().NotBeNull();
}
}