Skip to content

Commit

Permalink
#649 Acceptance tests (#1846)
Browse files Browse the repository at this point in the history
* Changes related to test case of issue 649

* #649 test cases

---------

Co-authored-by: Raman Maksimchuk <dotnet044@gmail.com>
  • Loading branch information
ks1990cn and raman-m committed Dec 8, 2023
1 parent ae6e547 commit 6b1f332
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions test/Ocelot.AcceptanceTests/RoutingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,18 +445,21 @@ public void should_return_response_200_when_host_has_trailing_slash()
.BDDfy();
}

[Fact]
public void should_return_ok_when_upstream_url_ends_with_forward_slash_but_template_does_not()
[Theory]
[InlineData("/products")]
[InlineData("/products/")]
public void should_return_ok_when_upstream_url_ends_with_forward_slash_but_template_does_not(string url)
{
var port = PortFinder.GetRandomPort();
var downstreamBasePath = "/products";

var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
{
new()
{
DownstreamPathTemplate = "/products",
DownstreamPathTemplate = downstreamBasePath,
DownstreamScheme = "http",
DownstreamHostAndPorts = new List<FileHostAndPort>
{
Expand All @@ -466,21 +469,60 @@ public void should_return_ok_when_upstream_url_ends_with_forward_slash_but_templ
Port = port,
},
},
UpstreamPathTemplate = "/products/",
UpstreamPathTemplate = downstreamBasePath+"/",
UpstreamHttpMethod = new List<string> { "Get" },
},
},
};

this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", "/products", 200, "Hello from Laura"))
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}", downstreamBasePath, 200, "Hello from Laura"))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/products"))
.When(x => _steps.WhenIGetUrlOnTheApiGateway(url))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
.BDDfy();
}


[Theory]
[InlineData("/account/authenticate")]
[InlineData("/account/authenticate/")]
[Trait("Issue", "649")]
public void should_fix_issue_649(string url)
{
var port = PortFinder.GetRandomPort();
var baseUrl = $"http://localhost:{port}";
var configuration = new FileConfiguration
{
Routes = new List<FileRoute>
{
new()
{
UpstreamPathTemplate = "/account/authenticate/",

DownstreamPathTemplate = "/authenticate",
DownstreamScheme = Uri.UriSchemeHttp,
DownstreamHostAndPorts = new()
{
new("localhost", port),
},
},
},
GlobalConfiguration =
{
BaseUrl = baseUrl,
},
};

this.Given(x => x.GivenThereIsAServiceRunningOn(baseUrl, "/authenticate", 200, "Hello from Laura"))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway(url))
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
.BDDfy();
}

[Fact]
public void should_return_not_found_when_upstream_url_ends_with_forward_slash_but_template_does_not()
{
Expand Down Expand Up @@ -1064,7 +1106,7 @@ public void should_fix_issue_271()
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
.BDDfy();
}
}

private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody)
{
Expand Down

0 comments on commit 6b1f332

Please sign in to comment.