Merge branch 'feature/603-bad-gateway' of https://github.com/jlukawska/Ocelot into jlukawska-feature/603-bad-gateway

This commit is contained in:
TomPallister
2020-04-11 18:01:05 +01:00
8 changed files with 70 additions and 5 deletions

View File

@ -141,7 +141,7 @@ namespace Ocelot.AcceptanceTests
}
[Fact]
public void should_return_response_500_when_using_http_one_to_talk_to_server_running_http_two()
public void should_return_response_502_when_using_http_one_to_talk_to_server_running_http_two()
{
var port = RandomPortFinder.GetRandomPort();
@ -177,7 +177,7 @@ namespace Ocelot.AcceptanceTests
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.InternalServerError))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.BadGateway))
.BDDfy();
}

View File

@ -16,6 +16,38 @@
{
_serviceHandler = new ServiceHandler();
_steps = new Steps();
}
[Fact]
public void should_return_bad_gateway_error_if_downstream_service_doesnt_respond()
{
var configuration = new FileConfiguration
{
ReRoutes = new List<FileReRoute>
{
new FileReRoute
{
DownstreamPathTemplate = "/",
UpstreamPathTemplate = "/",
UpstreamHttpMethod = new List<string> { "Get" },
DownstreamHostAndPorts = new List<FileHostAndPort>
{
new FileHostAndPort
{
Host = "localhost",
Port = 53877,
},
},
DownstreamScheme = "http",
},
},
};
this.Given(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.BadGateway))
.BDDfy();
}
[Fact]

View File

@ -89,7 +89,7 @@ namespace Ocelot.AcceptanceTests
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/"))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.InternalServerError))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.BadGateway))
.BDDfy();
}

View File

@ -50,6 +50,13 @@ namespace Ocelot.UnitTests.Responder
public void should_return_internal_server_error(OcelotErrorCode errorCode)
{
ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.InternalServerError);
}
[Theory]
[InlineData(OcelotErrorCode.ConnectionToDownstreamServiceError)]
public void should_return_bad_gateway_error(OcelotErrorCode errorCode)
{
ShouldMapErrorToStatusCode(errorCode, HttpStatusCode.BadGateway);
}
[Theory]
@ -125,7 +132,7 @@ namespace Ocelot.UnitTests.Responder
// If this test fails then it's because the number of error codes has changed.
// You should make the appropriate changes to the test cases here to ensure
// they cover all the error codes, and then modify this assertion.
Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(38, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
Enum.GetNames(typeof(OcelotErrorCode)).Length.ShouldBe(39, "Looks like the number of error codes has changed. Do you need to modify ErrorsToHttpStatusCodeMapper?");
}
private void ShouldMapErrorToStatusCode(OcelotErrorCode errorCode, HttpStatusCode expectedHttpStatusCode)