add log output checking in tests
This commit is contained in:
parent
08003d1fc3
commit
7ad2b5185b
|
|
@ -1,6 +1,5 @@
|
||||||
using SimpleHttpServer;
|
using SimpleHttpServer;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
namespace SimpleHttpServerTest;
|
namespace SimpleHttpServerTest;
|
||||||
|
|
||||||
|
|
@ -11,6 +10,7 @@ public class SimpleServerTest {
|
||||||
|
|
||||||
private HttpServer? activeServer = null;
|
private HttpServer? activeServer = null;
|
||||||
private HttpClient? activeHttpClient = null;
|
private HttpClient? activeHttpClient = null;
|
||||||
|
private bool failOnLogError = true;
|
||||||
private static string GetRequestPath(string url) => $"http://localhost:{PORT}/{url.TrimStart('/')}";
|
private static string GetRequestPath(string url) => $"http://localhost:{PORT}/{url.TrimStart('/')}";
|
||||||
private async Task RequestGetStringAsync(string path) => await activeHttpClient!.GetStringAsync(GetRequestPath(path));
|
private async Task RequestGetStringAsync(string path) => await activeHttpClient!.GetStringAsync(GetRequestPath(path));
|
||||||
private async Task<HttpResponseMessage> AssertGetStatusCodeAsync(string path, HttpStatusCode statusCode) {
|
private async Task<HttpResponseMessage> AssertGetStatusCodeAsync(string path, HttpStatusCode statusCode) {
|
||||||
|
|
@ -21,11 +21,18 @@ public class SimpleServerTest {
|
||||||
|
|
||||||
[TestInitialize]
|
[TestInitialize]
|
||||||
public void Init() {
|
public void Init() {
|
||||||
var conf = new SimpleHttpServerConfiguration();
|
var conf = new SimpleHttpServerConfiguration() {
|
||||||
|
DisableLogMessagePrinting = false,
|
||||||
|
LogMessageHandler = (LogOutputTopic topic, string message, LogOutputLevel logLevel) => {
|
||||||
|
if (failOnLogError && logLevel is LogOutputLevel.Error or LogOutputLevel.Fatal)
|
||||||
|
Assert.Fail($"An error was thrown in the log output:\n{topic} {message}");
|
||||||
|
}
|
||||||
|
};
|
||||||
if (activeServer != null)
|
if (activeServer != null)
|
||||||
throw new InvalidOperationException("Tried to create another httpserver instance when an existing one was already running.");
|
throw new InvalidOperationException("Tried to create another httpserver instance when an existing one was already running.");
|
||||||
|
|
||||||
Console.WriteLine("Starting server...");
|
Console.WriteLine("Starting server...");
|
||||||
|
failOnLogError = true;
|
||||||
activeServer = new HttpServer(PORT, conf);
|
activeServer = new HttpServer(PORT, conf);
|
||||||
activeServer.RegisterEndpointsFromType<TestEndpoints>();
|
activeServer.RegisterEndpointsFromType<TestEndpoints>();
|
||||||
activeServer.Start();
|
activeServer.Start();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user