mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 10:58:15 +08:00
massive refactor to handle creating load balancer first time a re route is called
This commit is contained in:
@ -44,7 +44,6 @@ namespace Ocelot.UnitTests.Configuration
|
||||
private Mock<IRateLimitOptionsCreator> _rateLimitOptions;
|
||||
private Mock<IRegionCreator> _regionCreator;
|
||||
private Mock<IHttpHandlerOptionsCreator> _httpHandlerOptionsCreator;
|
||||
private Mock<ILoadBalancerCreator> _lbCreator;
|
||||
|
||||
public FileConfigurationCreatorTests()
|
||||
{
|
||||
@ -65,11 +64,9 @@ namespace Ocelot.UnitTests.Configuration
|
||||
_rateLimitOptions = new Mock<IRateLimitOptionsCreator>();
|
||||
_regionCreator = new Mock<IRegionCreator>();
|
||||
_httpHandlerOptionsCreator = new Mock<IHttpHandlerOptionsCreator>();
|
||||
_lbCreator = new Mock<ILoadBalancerCreator>();
|
||||
|
||||
_ocelotConfigurationCreator = new FileOcelotConfigurationCreator(
|
||||
_fileConfig.Object, _validator.Object, _logger.Object,
|
||||
_lbCreator.Object,
|
||||
_qosProviderFactory.Object, _qosProviderHouse.Object, _claimsToThingCreator.Object,
|
||||
_authOptionsCreator.Object, _upstreamTemplatePatternCreator.Object, _requestIdKeyCreator.Object,
|
||||
_serviceProviderConfigCreator.Object, _qosOptionsCreator.Object, _fileReRouteOptionsCreator.Object,
|
||||
@ -189,32 +186,6 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_load_balancer()
|
||||
{
|
||||
var reRouteOptions = new ReRouteOptionsBuilder()
|
||||
.Build();
|
||||
|
||||
this.Given(x => x.GivenTheConfigIs(new FileConfiguration
|
||||
{
|
||||
ReRoutes = new List<FileReRoute>
|
||||
{
|
||||
new FileReRoute
|
||||
{
|
||||
DownstreamHost = "127.0.0.1",
|
||||
UpstreamPathTemplate = "/api/products/{productId}",
|
||||
DownstreamPathTemplate = "/products/{productId}",
|
||||
UpstreamHttpMethod = new List<string> { "Get" },
|
||||
}
|
||||
},
|
||||
}))
|
||||
.And(x => x.GivenTheConfigIsValid())
|
||||
.And(x => x.GivenTheFollowingOptionsAreReturned(reRouteOptions))
|
||||
.When(x => x.WhenICreateTheConfig())
|
||||
.And(x => x.ThenTheLoadBalancerCreatorIsCalledCorrectly())
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_use_downstream_host()
|
||||
{
|
||||
@ -320,12 +291,8 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithServiceProviderConfiguraion(new ServiceProviderConfigurationBuilder()
|
||||
.WithUseServiceDiscovery(true)
|
||||
.WithServiceDiscoveryProvider("consul")
|
||||
.WithServiceDiscoveryProviderHost("127.0.0.1")
|
||||
.WithServiceName("ProductService")
|
||||
.Build())
|
||||
.WithUseServiceDiscovery(true)
|
||||
.WithServiceName("ProductService")
|
||||
.Build()
|
||||
}))
|
||||
.BDDfy();
|
||||
@ -359,9 +326,7 @@ namespace Ocelot.UnitTests.Configuration
|
||||
.WithDownstreamPathTemplate("/products/{productId}")
|
||||
.WithUpstreamPathTemplate("/api/products/{productId}")
|
||||
.WithUpstreamHttpMethod(new List<string> { "Get" })
|
||||
.WithServiceProviderConfiguraion(new ServiceProviderConfigurationBuilder()
|
||||
.WithUseServiceDiscovery(false)
|
||||
.Build())
|
||||
.WithUseServiceDiscovery(false)
|
||||
.Build()
|
||||
}))
|
||||
.BDDfy();
|
||||
@ -604,20 +569,6 @@ namespace Ocelot.UnitTests.Configuration
|
||||
}
|
||||
}
|
||||
|
||||
private void ThenTheServiceConfigurationIs(ServiceProviderConfiguration expected)
|
||||
{
|
||||
for (int i = 0; i < _config.Data.ReRoutes.Count; i++)
|
||||
{
|
||||
var result = _config.Data.ReRoutes[i];
|
||||
result.ServiceProviderConfiguraion.DownstreamHost.ShouldBe(expected.DownstreamHost);
|
||||
result.ServiceProviderConfiguraion.DownstreamPort.ShouldBe(expected.DownstreamPort);
|
||||
result.ServiceProviderConfiguraion.ServiceDiscoveryProvider.ShouldBe(expected.ServiceDiscoveryProvider);
|
||||
result.ServiceProviderConfiguraion.ServiceName.ShouldBe(expected.ServiceName);
|
||||
result.ServiceProviderConfiguraion.ServiceProviderHost.ShouldBe(expected.ServiceProviderHost);
|
||||
result.ServiceProviderConfiguraion.ServiceProviderPort.ShouldBe(expected.ServiceProviderPort);
|
||||
}
|
||||
}
|
||||
|
||||
private void ThenTheAuthenticationOptionsAre(List<ReRoute> expectedReRoutes)
|
||||
{
|
||||
for (int i = 0; i < _config.Data.ReRoutes.Count; i++)
|
||||
@ -628,11 +579,6 @@ namespace Ocelot.UnitTests.Configuration
|
||||
}
|
||||
}
|
||||
|
||||
private void ThenTheLoadBalancerCreatorIsCalledCorrectly()
|
||||
{
|
||||
_lbCreator.Verify(x => x.SetupLoadBalancer(It.IsAny<ReRoute>()), Times.Once);
|
||||
}
|
||||
|
||||
private void GivenTheQosProviderFactoryReturns()
|
||||
{
|
||||
_qosProviderFactory
|
||||
|
@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Configuration.Repository;
|
||||
@ -36,7 +37,8 @@ namespace Ocelot.UnitTests.Configuration
|
||||
public void should_set_configuration()
|
||||
{
|
||||
var fileConfig = new FileConfiguration();
|
||||
var config = new OcelotConfiguration(new List<ReRoute>(), string.Empty);
|
||||
var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();
|
||||
var config = new OcelotConfiguration(new List<ReRoute>(), string.Empty, serviceProviderConfig);
|
||||
|
||||
this.Given(x => GivenTheFollowingConfiguration(fileConfig))
|
||||
.And(x => GivenTheRepoReturns(new OkResponse()))
|
||||
|
@ -92,6 +92,8 @@ namespace Ocelot.UnitTests.Configuration
|
||||
};
|
||||
|
||||
public string AdministrationPath {get;}
|
||||
|
||||
public ServiceProviderConfiguration ServiceProviderConfiguration => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.Provider;
|
||||
using Ocelot.Configuration.Repository;
|
||||
@ -27,9 +28,11 @@ namespace Ocelot.UnitTests.Configuration
|
||||
[Fact]
|
||||
public void should_get_config()
|
||||
{
|
||||
this.Given(x => x.GivenTheRepoReturns(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>(), string.Empty))))
|
||||
var serviceProviderConfig = new ServiceProviderConfigurationBuilder().Build();
|
||||
|
||||
this.Given(x => x.GivenTheRepoReturns(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>(), string.Empty, serviceProviderConfig))))
|
||||
.When(x => x.WhenIGetTheConfig())
|
||||
.Then(x => x.TheFollowingIsReturned(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>(), string.Empty))))
|
||||
.Then(x => x.TheFollowingIsReturned(new OkResponse<IOcelotConfiguration>(new OcelotConfiguration(new List<ReRoute>(), string.Empty, serviceProviderConfig))))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
|
@ -60,15 +60,12 @@ namespace Ocelot.UnitTests.Configuration
|
||||
|
||||
private void WhenICreate()
|
||||
{
|
||||
_result = _creator.Create(_reRoute, _globalConfig);
|
||||
_result = _creator.Create(_globalConfig);
|
||||
}
|
||||
|
||||
private void ThenTheConfigIs(ServiceProviderConfiguration expected)
|
||||
{
|
||||
_result.DownstreamHost.ShouldBe(expected.DownstreamHost);
|
||||
_result.DownstreamPort.ShouldBe(expected.DownstreamPort);
|
||||
_result.ServiceDiscoveryProvider.ShouldBe(expected.ServiceDiscoveryProvider);
|
||||
_result.ServiceName.ShouldBe(expected.ServiceName);
|
||||
_result.ServiceProviderHost.ShouldBe(expected.ServiceProviderHost);
|
||||
_result.ServiceProviderPort.ShouldBe(expected.ServiceProviderPort);
|
||||
}
|
||||
|
Reference in New Issue
Block a user