mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 10:18:17 +08:00
Reload config on change (#527)
* Reload config on change. Added test case. * added testing for adding the json with reloadOnChange = false
This commit is contained in:

committed by
Tom Pallister

parent
89f0cc786a
commit
ad8025df1b
@ -34,6 +34,7 @@ namespace Ocelot.AcceptanceTests
|
||||
using Butterfly;
|
||||
using Configuration.Repository;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Ocelot.Configuration.Creator;
|
||||
using MediaTypeHeaderValue = System.Net.Http.Headers.MediaTypeHeaderValue;
|
||||
|
||||
public class Steps : IDisposable
|
||||
@ -55,6 +56,18 @@ namespace Ocelot.AcceptanceTests
|
||||
_random = new Random();
|
||||
}
|
||||
|
||||
public async Task ThenConfigShouldBe(FileConfiguration fileConfig)
|
||||
{
|
||||
var internalConfigCreator = _ocelotServer.Host.Services.GetService<IInternalConfigurationCreator>();
|
||||
|
||||
var internalConfigRepo = _ocelotServer.Host.Services.GetService<IInternalConfigurationRepository>();
|
||||
var internalConfig = internalConfigRepo.Get();
|
||||
|
||||
var config = await internalConfigCreator.Create(fileConfig);
|
||||
|
||||
internalConfig.Data.RequestId.ShouldBe(config.Data.RequestId);
|
||||
}
|
||||
|
||||
public async Task StartFakeOcelotWithWebSockets()
|
||||
{
|
||||
_ocelotBuilder = new WebHostBuilder();
|
||||
@ -116,6 +129,34 @@ namespace Ocelot.AcceptanceTests
|
||||
File.WriteAllText(configurationPath, jsonConfiguration);
|
||||
}
|
||||
|
||||
public void GivenOcelotIsRunningReloadingConfig(bool shouldReload)
|
||||
{
|
||||
_webHostBuilder = new WebHostBuilder();
|
||||
|
||||
_webHostBuilder
|
||||
.ConfigureAppConfiguration((hostingContext, config) =>
|
||||
{
|
||||
config.SetBasePath(hostingContext.HostingEnvironment.ContentRootPath);
|
||||
var env = hostingContext.HostingEnvironment;
|
||||
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
|
||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: false);
|
||||
config.AddJsonFile("ocelot.json", optional: false, reloadOnChange: shouldReload);
|
||||
config.AddEnvironmentVariables();
|
||||
})
|
||||
.ConfigureServices(s =>
|
||||
{
|
||||
s.AddOcelot();
|
||||
})
|
||||
.Configure(app =>
|
||||
{
|
||||
app.UseOcelot().Wait();
|
||||
});
|
||||
|
||||
_ocelotServer = new TestServer(_webHostBuilder);
|
||||
|
||||
_ocelotClient = _ocelotServer.CreateClient();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This is annoying cos it should be in the constructor but we need to set up the file before calling startup so its a step.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user