mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 04:18:16 +08:00
Feature/another look at logging (#303)
* #212 - hacked websockets proxy together * faffing around * #212 hacking away :( * #212 websockets proxy middleware working * #212 map when for webockets working * #212 some test refactor * #212 temp commit * #212 websockets proxy working, tests passing...need to do some tidying and write docs * #212 more code coverage * #212 docs for websockets * #212 updated readme * #212 tidying up after websockets refactoring * #212 tidying up after websockets refactoring * #212 tidying up after websockets refactoring * changing logging levels and logging like ms reccomends with structured data rather than strings * more faffing * more fafin * #287 ocelot logger now only takes strings as it did take params then just turned them to strings, misleading, unit tests for logger and diagnosticlogger * #287 errors now logged as they happen * #287 more detail for logs requested in issue * #287 tidy up * #287 renamed * #287 always log context id * #287 fixed me being an idiot * #287 removed crap websockets unit test that isnt a unit test * #287 removed crap websockets unit test that isnt a unit test
This commit is contained in:
@ -1,9 +1,6 @@
|
||||
using Ocelot.Middleware;
|
||||
|
||||
namespace Ocelot.UnitTests.RequestId
|
||||
namespace Ocelot.UnitTests.RequestId
|
||||
{
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Ocelot.Infrastructure.RequestData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -21,6 +18,7 @@ namespace Ocelot.UnitTests.RequestId
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
using Ocelot.Request.Middleware;
|
||||
using Ocelot.Middleware;
|
||||
|
||||
public class ReRouteRequestIdMiddlewareTests
|
||||
{
|
||||
@ -142,6 +140,30 @@ namespace Ocelot.UnitTests.RequestId
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_update_if_global_request_id_is_same_as_re_route_request_id()
|
||||
{
|
||||
var downstreamRoute = new DownstreamRoute(new List<PlaceholderNameAndValue>(),
|
||||
new ReRouteBuilder()
|
||||
.WithDownstreamReRoute(new DownstreamReRouteBuilder()
|
||||
.WithDownstreamPathTemplate("any old string")
|
||||
.WithRequestIdKey("LSRequestId")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build())
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.Build());
|
||||
|
||||
var requestId = "alreadyset";
|
||||
|
||||
this.Given(x => x.GivenTheDownStreamRouteIs(downstreamRoute))
|
||||
.And(x => GivenTheRequestIdWasSetGlobally())
|
||||
.And(x => x.GivenTheRequestIdIsAddedToTheRequest("LSRequestId", requestId))
|
||||
.When(x => x.WhenICallTheMiddleware())
|
||||
.Then(x => x.ThenTheTraceIdIs(requestId))
|
||||
.And(x => ThenTheRequestIdIsNotUpdated())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void WhenICallTheMiddleware()
|
||||
{
|
||||
_middleware.Invoke(_downstreamContext).GetAwaiter().GetResult();
|
||||
@ -159,12 +181,17 @@ namespace Ocelot.UnitTests.RequestId
|
||||
|
||||
private void ThenTheRequestIdIsSaved()
|
||||
{
|
||||
_repo.Verify(x => x.Add<string>("RequestId", _value), Times.Once);
|
||||
_repo.Verify(x => x.Add("RequestId", _value), Times.Once);
|
||||
}
|
||||
|
||||
private void ThenTheRequestIdIsUpdated()
|
||||
{
|
||||
_repo.Verify(x => x.Update<string>("RequestId", _value), Times.Once);
|
||||
_repo.Verify(x => x.Update("RequestId", _value), Times.Once);
|
||||
}
|
||||
|
||||
private void ThenTheRequestIdIsNotUpdated()
|
||||
{
|
||||
_repo.Verify(x => x.Update("RequestId", _value), Times.Never);
|
||||
}
|
||||
|
||||
private void GivenTheDownStreamRouteIs(DownstreamRoute downstreamRoute)
|
||||
@ -182,15 +209,13 @@ namespace Ocelot.UnitTests.RequestId
|
||||
|
||||
private void ThenTheTraceIdIsAnything()
|
||||
{
|
||||
StringValues value;
|
||||
_downstreamContext.HttpContext.Response.Headers.TryGetValue("LSRequestId", out value);
|
||||
_downstreamContext.HttpContext.Response.Headers.TryGetValue("LSRequestId", out var value);
|
||||
value.First().ShouldNotBeNullOrEmpty();
|
||||
}
|
||||
|
||||
private void ThenTheTraceIdIs(string expected)
|
||||
{
|
||||
StringValues value;
|
||||
_downstreamContext.HttpContext.Response.Headers.TryGetValue("LSRequestId", out value);
|
||||
_downstreamContext.HttpContext.Response.Headers.TryGetValue("LSRequestId", out var value);
|
||||
value.First().ShouldBe(expected);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user