refactor: update Blazor testing guidelines and improve regex for hostname parsing in Caddy configuration
Some checks failed
Caddy Manager CI build / docker (push) Failing after 51s

This commit is contained in:
2025-07-23 15:29:00 +07:00
parent 063ed041b0
commit 24f76f8572
3 changed files with 39 additions and 11 deletions

View File

@@ -74,11 +74,9 @@ public class CaddyConfigurationParsingServiceTests
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(4); // Updated to reflect correct parsing of labels before blocks
result.Should().HaveCount(2); // Should only return outermost hostname declarations
result.Should().Contain("api.example.com");
result.Should().Contain("app.example.com");
result.Should().Contain("route /v1/*");
result.Should().Contain("route /v2/*");
}
/// <summary>
@@ -522,12 +520,9 @@ app.example.com {
// Assert
result.Should().NotBeNull();
result.Should().HaveCount(5);
result.Should().HaveCount(2); // Should only return outermost hostname declarations
result.Should().Contain("api.example.com");
result.Should().Contain("app.example.com");
result.Should().Contain("header");
result.Should().Contain("@cors");
result.Should().Contain("tls");
}
/// <summary>
@@ -669,5 +664,36 @@ api.test {
stopwatch.ElapsedMilliseconds.Should().BeLessThan(1000); // Should process in under 1 second
}
/// <summary>
/// Tests the parsing issue where the provided configuration is incorrectly parsed as 2 sites and 0 ports
/// instead of 1 site and 1 port.
/// </summary>
[Fact]
public void GetHostnamesAndPortsFromCaddyfileContent_WithProvidedConfiguration_ReturnsCorrectSiteAndPort()
{
// Arrange
var caddyfileContent = @"pika-auth.duydao.org {
reverse_proxy pikachu:3011 {
header_down X-Frame-Options """"
}
encode zstd gzip
}";
// Act
var hostnames = _service.GetHostnamesFromCaddyfileContent(caddyfileContent);
var ports = _service.GetReverseProxyPortsFromCaddyfileContent(caddyfileContent);
// Assert - Should have 1 site and 1 port
hostnames.Should().NotBeNull();
hostnames.Should().HaveCount(1);
hostnames.Should().Contain("pika-auth.duydao.org");
ports.Should().NotBeNull();
ports.Should().HaveCount(1);
ports.Should().Contain(3011);
}
#endregion
}