- 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.
145 lines
4.0 KiB
C#
145 lines
4.0 KiB
C#
using FluentAssertions;
|
|
using StellaOps.Microservice;
|
|
using Xunit;
|
|
|
|
namespace StellaOps.Microservice.Tests;
|
|
|
|
/// <summary>
|
|
/// Tests for MicroserviceYamlConfig and EndpointOverrideConfig classes.
|
|
/// </summary>
|
|
public class MicroserviceYamlConfigTests
|
|
{
|
|
[Fact]
|
|
public void MicroserviceYamlConfig_DefaultsToEmptyEndpoints()
|
|
{
|
|
var config = new MicroserviceYamlConfig();
|
|
|
|
config.Endpoints.Should().NotBeNull();
|
|
config.Endpoints.Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void EndpointOverrideConfig_DefaultsToEmptyStrings()
|
|
{
|
|
var config = new EndpointOverrideConfig();
|
|
|
|
config.Method.Should().Be(string.Empty);
|
|
config.Path.Should().Be(string.Empty);
|
|
config.DefaultTimeout.Should().BeNull();
|
|
config.SupportsStreaming.Should().BeNull();
|
|
config.RequiringClaims.Should().BeNull();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("30s", 30)]
|
|
[InlineData("60s", 60)]
|
|
[InlineData("1s", 1)]
|
|
[InlineData("120S", 120)] // Case insensitive
|
|
public void GetDefaultTimeoutAsTimeSpan_ParsesSeconds(string input, int expectedSeconds)
|
|
{
|
|
var config = new EndpointOverrideConfig { DefaultTimeout = input };
|
|
|
|
var result = config.GetDefaultTimeoutAsTimeSpan();
|
|
|
|
result.Should().Be(TimeSpan.FromSeconds(expectedSeconds));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("5m", 5)]
|
|
[InlineData("10m", 10)]
|
|
[InlineData("1m", 1)]
|
|
[InlineData("30M", 30)] // Case insensitive
|
|
public void GetDefaultTimeoutAsTimeSpan_ParsesMinutes(string input, int expectedMinutes)
|
|
{
|
|
var config = new EndpointOverrideConfig { DefaultTimeout = input };
|
|
|
|
var result = config.GetDefaultTimeoutAsTimeSpan();
|
|
|
|
result.Should().Be(TimeSpan.FromMinutes(expectedMinutes));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("1h", 1)]
|
|
[InlineData("2h", 2)]
|
|
[InlineData("24h", 24)]
|
|
[InlineData("1H", 1)] // Case insensitive
|
|
public void GetDefaultTimeoutAsTimeSpan_ParsesHours(string input, int expectedHours)
|
|
{
|
|
var config = new EndpointOverrideConfig { DefaultTimeout = input };
|
|
|
|
var result = config.GetDefaultTimeoutAsTimeSpan();
|
|
|
|
result.Should().Be(TimeSpan.FromHours(expectedHours));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("00:00:30", 30)]
|
|
[InlineData("00:05:00", 300)]
|
|
[InlineData("01:00:00", 3600)]
|
|
[InlineData("00:01:30", 90)]
|
|
public void GetDefaultTimeoutAsTimeSpan_ParsesTimeSpanFormat(string input, int expectedSeconds)
|
|
{
|
|
var config = new EndpointOverrideConfig { DefaultTimeout = input };
|
|
|
|
var result = config.GetDefaultTimeoutAsTimeSpan();
|
|
|
|
result.Should().Be(TimeSpan.FromSeconds(expectedSeconds));
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData(" ")]
|
|
public void GetDefaultTimeoutAsTimeSpan_ReturnsNullForEmptyValues(string? input)
|
|
{
|
|
var config = new EndpointOverrideConfig { DefaultTimeout = input };
|
|
|
|
var result = config.GetDefaultTimeoutAsTimeSpan();
|
|
|
|
result.Should().BeNull();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("invalid")]
|
|
[InlineData("abc")]
|
|
[InlineData("30x")]
|
|
public void GetDefaultTimeoutAsTimeSpan_ReturnsNullForInvalidFormats(string input)
|
|
{
|
|
var config = new EndpointOverrideConfig { DefaultTimeout = input };
|
|
|
|
var result = config.GetDefaultTimeoutAsTimeSpan();
|
|
|
|
result.Should().BeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void ClaimRequirementConfig_ToClaimRequirement_ConvertsCorrectly()
|
|
{
|
|
var config = new ClaimRequirementConfig
|
|
{
|
|
Type = "role",
|
|
Value = "admin"
|
|
};
|
|
|
|
var result = config.ToClaimRequirement();
|
|
|
|
result.Type.Should().Be("role");
|
|
result.Value.Should().Be("admin");
|
|
}
|
|
|
|
[Fact]
|
|
public void ClaimRequirementConfig_ToClaimRequirement_HandlesNullValue()
|
|
{
|
|
var config = new ClaimRequirementConfig
|
|
{
|
|
Type = "authenticated",
|
|
Value = null
|
|
};
|
|
|
|
var result = config.ToClaimRequirement();
|
|
|
|
result.Type.Should().Be("authenticated");
|
|
result.Value.Should().BeNull();
|
|
}
|
|
}
|