mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 00:32:50 +08:00
changed file config stuff to just use app base directory
This commit is contained in:
parent
816221c7a6
commit
fa47663259
@ -31,6 +31,7 @@ using Ocelot.Requester;
|
||||
using Ocelot.Requester.QoS;
|
||||
using Ocelot.Responder;
|
||||
using Ocelot.ServiceDiscovery;
|
||||
using Ocelot.Services;
|
||||
|
||||
namespace Ocelot.DependencyInjection
|
||||
{
|
||||
@ -62,6 +63,7 @@ namespace Ocelot.DependencyInjection
|
||||
{
|
||||
services.AddMvcCore().AddJsonFormatters();
|
||||
services.AddLogging();
|
||||
services.AddSingleton<IGetFileConfiguration, GetFileConfiguration>();
|
||||
services.AddSingleton<IQosProviderHouse, QosProviderHouse>();
|
||||
services.AddSingleton<IQoSProviderFactory, QoSProviderFactory>();
|
||||
services.AddSingleton<IServiceDiscoveryProviderFactory, ServiceDiscoveryProviderFactory>();
|
||||
|
@ -10,7 +10,7 @@ namespace Ocelot.Services
|
||||
{
|
||||
public Response<FileConfiguration> Invoke()
|
||||
{
|
||||
var configFilePath = "configuration.json";
|
||||
var configFilePath = $"{AppContext.BaseDirectory}/configuration.json";
|
||||
var json = File.ReadAllText(configFilePath);
|
||||
var fileConfiguration = JsonConvert.DeserializeObject<FileConfiguration>(json);
|
||||
return new OkResponse<FileConfiguration>(fileConfiguration);
|
||||
|
@ -36,7 +36,6 @@ namespace Ocelot.AcceptanceTests
|
||||
.And(x => _steps.GivenOcelotIsRunning())
|
||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/administration/configuration"))
|
||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||
.And(x => _steps.ThenTheResponseBodyShouldBe("hi from re routes controller"))
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
@ -56,7 +55,18 @@ namespace Ocelot.AcceptanceTests
|
||||
DownstreamHost = "localhost",
|
||||
DownstreamPort = 80,
|
||||
DownstreamScheme = "https",
|
||||
DownstreamPathTemplate = "/"
|
||||
DownstreamPathTemplate = "/",
|
||||
UpstreamHttpMethod = "get",
|
||||
UpstreamPathTemplate = "/"
|
||||
},
|
||||
new FileReRoute()
|
||||
{
|
||||
DownstreamHost = "localhost",
|
||||
DownstreamPort = 80,
|
||||
DownstreamScheme = "https",
|
||||
DownstreamPathTemplate = "/",
|
||||
UpstreamHttpMethod = "get",
|
||||
UpstreamPathTemplate = "/test"
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -69,27 +79,6 @@ namespace Ocelot.AcceptanceTests
|
||||
.BDDfy();
|
||||
}
|
||||
|
||||
private void GivenThereIsAServiceRunningOn(string url, int statusCode, string responseBody)
|
||||
{
|
||||
_builder = new WebHostBuilder()
|
||||
.UseUrls(url)
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseIISIntegration()
|
||||
.UseUrls(url)
|
||||
.Configure(app =>
|
||||
{
|
||||
app.Run(async context =>
|
||||
{
|
||||
context.Response.StatusCode = statusCode;
|
||||
await context.Response.WriteAsync(responseBody);
|
||||
});
|
||||
})
|
||||
.Build();
|
||||
|
||||
_builder.Start();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_builder?.Dispose();
|
||||
|
@ -31,7 +31,7 @@ namespace Ocelot.AcceptanceTests
|
||||
private BearerToken _token;
|
||||
public HttpClient OcelotClient => _ocelotClient;
|
||||
public string RequestIdKey = "OcRequestId";
|
||||
private Random _random;
|
||||
private readonly Random _random;
|
||||
|
||||
public Steps()
|
||||
{
|
||||
@ -91,6 +91,8 @@ namespace Ocelot.AcceptanceTests
|
||||
response.ReRoutes[i].DownstreamPathTemplate.ShouldBe(expected.ReRoutes[i].DownstreamPathTemplate);
|
||||
response.ReRoutes[i].DownstreamPort.ShouldBe(expected.ReRoutes[i].DownstreamPort);
|
||||
response.ReRoutes[i].DownstreamScheme.ShouldBe(expected.ReRoutes[i].DownstreamScheme);
|
||||
response.ReRoutes[i].UpstreamPathTemplate.ShouldBe(expected.ReRoutes[i].UpstreamPathTemplate);
|
||||
response.ReRoutes[i].UpstreamHttpMethod.ShouldBe(expected.ReRoutes[i].UpstreamHttpMethod);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,36 +1,9 @@
|
||||
namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
using System.Runtime.InteropServices;
|
||||
using System;
|
||||
|
||||
namespace Ocelot.AcceptanceTests
|
||||
{
|
||||
public static class TestConfiguration
|
||||
{
|
||||
public static double Version => 1.1;
|
||||
public static string ConfigurationPath => GetConfigurationPath();
|
||||
|
||||
public static string GetConfigurationPath()
|
||||
{
|
||||
var osArchitecture = RuntimeInformation.OSArchitecture.ToString();
|
||||
|
||||
if(RuntimeInformation.OSDescription.ToLower().Contains("darwin"))
|
||||
{
|
||||
return FormatConfigurationPath("osx.10.11", osArchitecture);
|
||||
}
|
||||
|
||||
if(RuntimeInformation.OSDescription.ToLower().Contains("microsoft windows 10"))
|
||||
{
|
||||
return FormatConfigurationPath("win10", osArchitecture);
|
||||
}
|
||||
|
||||
return FormatConfigurationPath("win7", osArchitecture);
|
||||
}
|
||||
|
||||
private static string FormatConfigurationPath(string oSDescription, string osArchitecture)
|
||||
{
|
||||
var runTime = $"{oSDescription}-{osArchitecture}".ToLower();
|
||||
|
||||
var configPath = $"./test/Ocelot.AcceptanceTests/bin/Debug/netcoreapp{Version}/{runTime}/configuration.json";
|
||||
|
||||
return configPath;
|
||||
}
|
||||
public static string ConfigurationPath => $"{AppContext.BaseDirectory}/configuration.json";
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using Ocelot.Configuration;
|
||||
@ -14,7 +15,7 @@ namespace Ocelot.UnitTests.Services
|
||||
{
|
||||
public class GetFileConfigurationTests
|
||||
{
|
||||
private IGetFileConfiguration _getReRoutes;
|
||||
private readonly IGetFileConfiguration _getReRoutes;
|
||||
private FileConfiguration _result;
|
||||
|
||||
public GetFileConfigurationTests()
|
||||
@ -59,7 +60,8 @@ namespace Ocelot.UnitTests.Services
|
||||
|
||||
private void GivenTheConfigurationIs(FileConfiguration fileConfiguration)
|
||||
{
|
||||
var configurationPath = "configuration.json";
|
||||
var configurationPath = $"{AppContext.BaseDirectory}/configuration.json";
|
||||
|
||||
var jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration);
|
||||
|
||||
if (File.Exists(configurationPath))
|
||||
@ -89,7 +91,6 @@ namespace Ocelot.UnitTests.Services
|
||||
_result.ReRoutes[i].DownstreamPathTemplate.ShouldBe(expected.ReRoutes[i].DownstreamPathTemplate);
|
||||
_result.ReRoutes[i].DownstreamPort.ShouldBe(expected.ReRoutes[i].DownstreamPort);
|
||||
_result.ReRoutes[i].DownstreamScheme.ShouldBe(expected.ReRoutes[i].DownstreamScheme);
|
||||
//todo -- add more!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user