mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 10:38:15 +08:00
fixed problems where routes were not mathing
This commit is contained in:
@ -56,6 +56,80 @@ namespace Ocelot.AcceptanceTests
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_care_about_no_trailing()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "http://localhost:51879/products",
|
||||
UpstreamTemplate = "/products/",
|
||||
UpstreamHttpMethod = "Get",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/products", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/products"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_not_care_about_trailing()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "http://localhost:51879/products",
|
||||
UpstreamTemplate = "/products",
|
||||
UpstreamHttpMethod = "Get",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/products", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/products/"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => _steps.ThenTheResponseBodyShouldBe("Hello from Laura"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_not_found()
|
||||
{
|
||||
var configuration = new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamTemplate = "http://localhost:51879/products",
|
||||
UpstreamTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = "Get",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.Given(x => x.GivenThereIsAServiceRunningOn("http://localhost:51879/products", 200, "Hello from Laura"))
|
||||
.And(x => _steps.GivenThereIsAConfiguration(configuration))
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/products/"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.NotFound))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_return_response_200_with_complex_url()
|
||||
{
|
||||
|
@ -137,6 +137,12 @@
|
||||
"UpstreamTemplate": "/customers/{customerId}",
|
||||
"UpstreamHttpMethod": "Delete",
|
||||
"FileCacheOptions": { "TtlSeconds": 15 }
|
||||
},
|
||||
{
|
||||
"DownstreamTemplate": "http://jsonplaceholder.typicode.com/posts",
|
||||
"UpstreamTemplate": "/posts/",
|
||||
"UpstreamHttpMethod": "Get",
|
||||
"FileCacheOptions": { "TtlSeconds": 15 }
|
||||
}
|
||||
],
|
||||
"GlobalConfiguration": {
|
||||
|
@ -59,7 +59,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*$")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
|
||||
.Build()
|
||||
}))
|
||||
.BDDfy();
|
||||
@ -88,7 +88,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*$")
|
||||
.WithUpstreamTemplatePattern("(?i)/api/products/.*/$")
|
||||
.Build()
|
||||
}))
|
||||
.BDDfy();
|
||||
@ -118,7 +118,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*$")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
.Build()
|
||||
}))
|
||||
.BDDfy();
|
||||
@ -152,7 +152,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*$")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
.WithRequestIdKey("blahhhh")
|
||||
.Build()
|
||||
}))
|
||||
@ -183,7 +183,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*$")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
.Build()
|
||||
}))
|
||||
.BDDfy();
|
||||
@ -198,7 +198,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*$")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
.WithAuthenticationProvider("IdentityServer")
|
||||
.WithAuthenticationProviderUrl("http://localhost:51888")
|
||||
.WithRequireHttps(false)
|
||||
@ -261,7 +261,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*$")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/$")
|
||||
.WithAuthenticationProvider("IdentityServer")
|
||||
.WithAuthenticationProviderUrl("http://localhost:51888")
|
||||
.WithRequireHttps(false)
|
||||
@ -323,7 +323,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamTemplate("/products/{productId}")
|
||||
.WithUpstreamTemplate("/api/products/{productId}/variants/{variantId}")
|
||||
.WithUpstreamHttpMethod("Get")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/variants/.*$")
|
||||
.WithUpstreamTemplatePattern("/api/products/.*/variants/.*/$")
|
||||
.Build()
|
||||
}))
|
||||
.BDDfy();
|
||||
|
@ -148,7 +148,6 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder.UrlMatcher
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
|
||||
private void GivenIHaveAUpstreamPath(string downstreamPath)
|
||||
{
|
||||
_downstreamUrlPath = downstreamPath;
|
||||
|
Reference in New Issue
Block a user