Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuki committed Dec 19, 2024
1 parent e2e4607 commit 2521356
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/YetAnotherHttpHandler.Test/UdsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Security.Cryptography.X509Certificates;
using Cysharp.Net.Http;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Xunit.Abstractions;

namespace _YetAnotherHttpHandler.Test;

public class UdsTest(ITestOutputHelper testOutputHelper) : Http2TestBase(testOutputHelper)
{
private readonly string _udsPath = Path.Combine(Path.GetTempPath(), $"yaha-uds-test-{Guid.NewGuid()}");
protected override YetAnotherHttpHandler CreateHandler()
{
return new YetAnotherHttpHandler()
{
UnixDomainSocketPath = _udsPath,
Http2Only = true,
};
}

protected override Task<TestWebAppServer> LaunchServerAsyncCore<T>(Action<WebApplicationBuilder>? configure = null)
{
return LaunchServerAsync<T>(TestWebAppServerListenMode.SecureHttp2Only, builder =>
{
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenUnixSocket(_udsPath, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
});

// hyperlocal uses the 'unix' scheme and passes the URI to hyper. As a result, the ':scheme' header in the request is set to 'unix'.
// By default, Kestrel does not accept non-HTTP schemes. To allow non-HTTP schemes, we need to set 'AllowAlternateSchemes' to true.
options.AllowAlternateSchemes = true;
});

configure?.Invoke(builder);
});
}
}

0 comments on commit 2521356

Please sign in to comment.