mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 06:48:16 +08:00
hacked together load balancing reroutes in fileconfig (#211)
* hacked together load balancing reroutes in fileconfig * some renaming and refactoring * more renames * hacked away the old config json * test for issue 213 * renamed key * dont share ports * oops * updated docs * mvoed docs around * port being used
This commit is contained in:
@ -0,0 +1,122 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Configuration;
|
||||
using Ocelot.Configuration.Builder;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using Ocelot.Configuration.File;
|
||||
using Shouldly;
|
||||
using TestStack.BDDfy;
|
||||
using Xunit;
|
||||
|
||||
namespace Ocelot.UnitTests.Configuration
|
||||
{
|
||||
public class DownstreamAddressesCreatorTests
|
||||
{
|
||||
public DownstreamAddressesCreator _creator;
|
||||
private FileReRoute _reRoute;
|
||||
private List<DownstreamHostAndPort> _result;
|
||||
|
||||
public DownstreamAddressesCreatorTests()
|
||||
{
|
||||
_creator = new DownstreamAddressesCreator();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_do_nothing()
|
||||
{
|
||||
var reRoute = new FileReRoute
|
||||
{
|
||||
};
|
||||
|
||||
var expected = new List<DownstreamHostAndPort>
|
||||
{
|
||||
};
|
||||
|
||||
this.Given(x => GivenTheFollowingReRoute(reRoute))
|
||||
.When(x => WhenICreate())
|
||||
.Then(x => TheThenFollowingIsReturned(expected))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_downstream_addresses_from_old_downstream_path_and_port()
|
||||
{
|
||||
var reRoute = new FileReRoute
|
||||
{
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "test",
|
||||
Port = 80
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var expected = new List<DownstreamHostAndPort>
|
||||
{
|
||||
new DownstreamHostAndPort("test", 80),
|
||||
};
|
||||
|
||||
this.Given(x => GivenTheFollowingReRoute(reRoute))
|
||||
.When(x => WhenICreate())
|
||||
.Then(x => TheThenFollowingIsReturned(expected))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void should_create_downstream_addresses_from_downstream_host_and_ports()
|
||||
{
|
||||
var reRoute = new FileReRoute
|
||||
{
|
||||
DownstreamHostAndPorts = new List<FileHostAndPort>
|
||||
{
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "test",
|
||||
Port = 80
|
||||
},
|
||||
new FileHostAndPort
|
||||
{
|
||||
Host = "west",
|
||||
Port = 443
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var expected = new List<DownstreamHostAndPort>
|
||||
{
|
||||
new DownstreamHostAndPort("test", 80),
|
||||
new DownstreamHostAndPort("west", 443)
|
||||
};
|
||||
|
||||
this.Given(x => GivenTheFollowingReRoute(reRoute))
|
||||
.When(x => WhenICreate())
|
||||
.Then(x => TheThenFollowingIsReturned(expected))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenTheFollowingReRoute(FileReRoute reRoute)
|
||||
{
|
||||
_reRoute = reRoute;
|
||||
}
|
||||
|
||||
private void WhenICreate()
|
||||
{
|
||||
_result = _creator.Create(_reRoute);
|
||||
}
|
||||
|
||||
private void TheThenFollowingIsReturned(List<DownstreamHostAndPort> expecteds)
|
||||
{
|
||||
_result.Count.ShouldBe(expecteds.Count);
|
||||
|
||||
for (int i = 0; i < _result.Count; i++)
|
||||
{
|
||||
var result = _result[i];
|
||||
var expected = expecteds[i];
|
||||
|
||||
result.Host.ShouldBe(expected.Host);
|
||||
result.Port.ShouldBe(expected.Port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user