Skip to content

Commit

Permalink
#340 getting old routing tests to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Gardham-Pallister committed May 9, 2018
1 parent e686896 commit 81f920f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,22 @@ public DownstreamRouteFinderFactory(IServiceProvider provider)

public IDownstreamRouteFinder Get(IInternalConfiguration config)
{
if(!config.ReRoutes.Any())
if(!config.ReRoutes.Any() && IsServiceDiscovery(config.ServiceProviderConfiguration))
{
return _providers[nameof(DownstreamRouteCreator)];
}

return _providers[nameof(DownstreamRouteFinder)];
}

private bool IsServiceDiscovery(ServiceProviderConfiguration config)
{
if(!string.IsNullOrEmpty(config?.Host) || config?.Port > 0)
{
return true;
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public ConsulServiceDiscoveryProvider(ConsulRegistryConfiguration config, IOcelo
{;
_logger = factory.CreateLogger<ConsulServiceDiscoveryProvider>();

//todo - set these in the builder, not here? Is hacky now because we need to run logic in route finder factory to
//see if serviee discovery set
var consulHost = string.IsNullOrEmpty(config?.Host) ? "localhost" : config.Host;

var consulPort = config?.Port ?? 8500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,26 @@ public void should_return_downstream_route_finder()
}

[Fact]
public void should_return_downstream_route_creator()
public void should_return_downstream_route_finder_as_no_service_discovery()
{
var spConfig = new ServiceProviderConfigurationBuilder().Build();
var reRoutes = new List<ReRoute>
{
};
IInternalConfiguration config = new InternalConfiguration(reRoutes, "", spConfig, "");
var result = _factory.Get(config);
result.ShouldBeOfType<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteFinder>();
}

[Fact]
public void should_return_downstream_route_creator()
{
var spConfig = new ServiceProviderConfigurationBuilder().WithHost("test").WithPort(50).Build();
var reRoutes = new List<ReRoute>
{
};
IInternalConfiguration config = new InternalConfiguration(reRoutes, "", spConfig, "");
var result = _factory.Get(config);
result.ShouldBeOfType<Ocelot.DownstreamRouteFinder.Finder.DownstreamRouteCreator>();
}
}
Expand Down

0 comments on commit 81f920f

Please sign in to comment.