Add unit tests for Router configuration and transport layers
- Implemented tests for RouterConfig, RoutingOptions, StaticInstanceConfig, and RouterConfigOptions to ensure default values are set correctly. - Added tests for RouterConfigProvider to validate configurations and ensure defaults are returned when no file is specified. - Created tests for ConfigValidationResult to check success and error scenarios. - Developed tests for ServiceCollectionExtensions to verify service registration for RouterConfig. - Introduced UdpTransportTests to validate serialization, connection, request-response, and error handling in UDP transport. - Added scripts for signing authority gaps and hashing DevPortal SDK snippets.
This commit is contained in:
53
examples/router/src/Examples.Gateway/Program.cs
Normal file
53
examples/router/src/Examples.Gateway/Program.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using StellaOps.Gateway.WebService;
|
||||
using StellaOps.Gateway.WebService.Authorization;
|
||||
using StellaOps.Gateway.WebService.Middleware;
|
||||
using StellaOps.Router.Config;
|
||||
using StellaOps.Router.Transport.InMemory;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Router configuration from YAML
|
||||
builder.Services.AddRouterConfig(options =>
|
||||
{
|
||||
options.ConfigPath = "router.yaml";
|
||||
options.EnableHotReload = true;
|
||||
});
|
||||
|
||||
// Gateway routing services
|
||||
builder.Services.AddGatewayRouting(builder.Configuration);
|
||||
|
||||
// In-memory transport for demo (can switch to TCP/TLS for production)
|
||||
builder.Services.AddInMemoryTransport();
|
||||
|
||||
// Authority integration (no-op for demo)
|
||||
builder.Services.AddNoOpAuthorityIntegration();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Middleware pipeline
|
||||
app.UseForwardedHeaders();
|
||||
app.UseMiddleware<PayloadLimitsMiddleware>();
|
||||
app.UseAuthentication();
|
||||
app.UseMiddleware<EndpointResolutionMiddleware>();
|
||||
app.UseClaimsAuthorization();
|
||||
app.UseMiddleware<RoutingDecisionMiddleware>();
|
||||
|
||||
// Simple health endpoint
|
||||
app.MapGet("/health", () => Results.Ok(new { status = "healthy" }));
|
||||
|
||||
// Catch-all for routed requests
|
||||
app.MapFallback(async context =>
|
||||
{
|
||||
// The RoutingDecisionMiddleware would have dispatched the request
|
||||
// If we reach here, no route was found
|
||||
context.Response.StatusCode = 404;
|
||||
await context.Response.WriteAsJsonAsync(new { error = "Not Found", message = "No matching endpoint" });
|
||||
});
|
||||
|
||||
app.Run();
|
||||
|
||||
// Partial class for WebApplicationFactory integration testing
|
||||
namespace Examples.Gateway
|
||||
{
|
||||
public partial class Program { }
|
||||
}
|
||||
Reference in New Issue
Block a user