mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22: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.Requester.QoS;
|
||||||
using Ocelot.Responder;
|
using Ocelot.Responder;
|
||||||
using Ocelot.ServiceDiscovery;
|
using Ocelot.ServiceDiscovery;
|
||||||
|
using Ocelot.Services;
|
||||||
|
|
||||||
namespace Ocelot.DependencyInjection
|
namespace Ocelot.DependencyInjection
|
||||||
{
|
{
|
||||||
@ -62,6 +63,7 @@ namespace Ocelot.DependencyInjection
|
|||||||
{
|
{
|
||||||
services.AddMvcCore().AddJsonFormatters();
|
services.AddMvcCore().AddJsonFormatters();
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
|
services.AddSingleton<IGetFileConfiguration, GetFileConfiguration>();
|
||||||
services.AddSingleton<IQosProviderHouse, QosProviderHouse>();
|
services.AddSingleton<IQosProviderHouse, QosProviderHouse>();
|
||||||
services.AddSingleton<IQoSProviderFactory, QoSProviderFactory>();
|
services.AddSingleton<IQoSProviderFactory, QoSProviderFactory>();
|
||||||
services.AddSingleton<IServiceDiscoveryProviderFactory, ServiceDiscoveryProviderFactory>();
|
services.AddSingleton<IServiceDiscoveryProviderFactory, ServiceDiscoveryProviderFactory>();
|
||||||
|
@ -10,7 +10,7 @@ namespace Ocelot.Services
|
|||||||
{
|
{
|
||||||
public Response<FileConfiguration> Invoke()
|
public Response<FileConfiguration> Invoke()
|
||||||
{
|
{
|
||||||
var configFilePath = "configuration.json";
|
var configFilePath = $"{AppContext.BaseDirectory}/configuration.json";
|
||||||
var json = File.ReadAllText(configFilePath);
|
var json = File.ReadAllText(configFilePath);
|
||||||
var fileConfiguration = JsonConvert.DeserializeObject<FileConfiguration>(json);
|
var fileConfiguration = JsonConvert.DeserializeObject<FileConfiguration>(json);
|
||||||
return new OkResponse<FileConfiguration>(fileConfiguration);
|
return new OkResponse<FileConfiguration>(fileConfiguration);
|
||||||
|
@ -36,7 +36,6 @@ namespace Ocelot.AcceptanceTests
|
|||||||
.And(x => _steps.GivenOcelotIsRunning())
|
.And(x => _steps.GivenOcelotIsRunning())
|
||||||
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/administration/configuration"))
|
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/administration/configuration"))
|
||||||
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
.Then(x => _steps.ThenTheStatusCodeShouldBe(HttpStatusCode.OK))
|
||||||
.And(x => _steps.ThenTheResponseBodyShouldBe("hi from re routes controller"))
|
|
||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +55,18 @@ namespace Ocelot.AcceptanceTests
|
|||||||
DownstreamHost = "localhost",
|
DownstreamHost = "localhost",
|
||||||
DownstreamPort = 80,
|
DownstreamPort = 80,
|
||||||
DownstreamScheme = "https",
|
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();
|
.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()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_builder?.Dispose();
|
_builder?.Dispose();
|
||||||
|
@ -31,7 +31,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
private BearerToken _token;
|
private BearerToken _token;
|
||||||
public HttpClient OcelotClient => _ocelotClient;
|
public HttpClient OcelotClient => _ocelotClient;
|
||||||
public string RequestIdKey = "OcRequestId";
|
public string RequestIdKey = "OcRequestId";
|
||||||
private Random _random;
|
private readonly Random _random;
|
||||||
|
|
||||||
public Steps()
|
public Steps()
|
||||||
{
|
{
|
||||||
@ -91,6 +91,8 @@ namespace Ocelot.AcceptanceTests
|
|||||||
response.ReRoutes[i].DownstreamPathTemplate.ShouldBe(expected.ReRoutes[i].DownstreamPathTemplate);
|
response.ReRoutes[i].DownstreamPathTemplate.ShouldBe(expected.ReRoutes[i].DownstreamPathTemplate);
|
||||||
response.ReRoutes[i].DownstreamPort.ShouldBe(expected.ReRoutes[i].DownstreamPort);
|
response.ReRoutes[i].DownstreamPort.ShouldBe(expected.ReRoutes[i].DownstreamPort);
|
||||||
response.ReRoutes[i].DownstreamScheme.ShouldBe(expected.ReRoutes[i].DownstreamScheme);
|
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;
|
||||||
{
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
|
namespace Ocelot.AcceptanceTests
|
||||||
|
{
|
||||||
public static class TestConfiguration
|
public static class TestConfiguration
|
||||||
{
|
{
|
||||||
public static double Version => 1.1;
|
public static string ConfigurationPath => $"{AppContext.BaseDirectory}/configuration.json";
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Ocelot.Configuration;
|
using Ocelot.Configuration;
|
||||||
@ -14,7 +15,7 @@ namespace Ocelot.UnitTests.Services
|
|||||||
{
|
{
|
||||||
public class GetFileConfigurationTests
|
public class GetFileConfigurationTests
|
||||||
{
|
{
|
||||||
private IGetFileConfiguration _getReRoutes;
|
private readonly IGetFileConfiguration _getReRoutes;
|
||||||
private FileConfiguration _result;
|
private FileConfiguration _result;
|
||||||
|
|
||||||
public GetFileConfigurationTests()
|
public GetFileConfigurationTests()
|
||||||
@ -59,7 +60,8 @@ namespace Ocelot.UnitTests.Services
|
|||||||
|
|
||||||
private void GivenTheConfigurationIs(FileConfiguration fileConfiguration)
|
private void GivenTheConfigurationIs(FileConfiguration fileConfiguration)
|
||||||
{
|
{
|
||||||
var configurationPath = "configuration.json";
|
var configurationPath = $"{AppContext.BaseDirectory}/configuration.json";
|
||||||
|
|
||||||
var jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration);
|
var jsonConfiguration = JsonConvert.SerializeObject(fileConfiguration);
|
||||||
|
|
||||||
if (File.Exists(configurationPath))
|
if (File.Exists(configurationPath))
|
||||||
@ -89,7 +91,6 @@ namespace Ocelot.UnitTests.Services
|
|||||||
_result.ReRoutes[i].DownstreamPathTemplate.ShouldBe(expected.ReRoutes[i].DownstreamPathTemplate);
|
_result.ReRoutes[i].DownstreamPathTemplate.ShouldBe(expected.ReRoutes[i].DownstreamPathTemplate);
|
||||||
_result.ReRoutes[i].DownstreamPort.ShouldBe(expected.ReRoutes[i].DownstreamPort);
|
_result.ReRoutes[i].DownstreamPort.ShouldBe(expected.ReRoutes[i].DownstreamPort);
|
||||||
_result.ReRoutes[i].DownstreamScheme.ShouldBe(expected.ReRoutes[i].DownstreamScheme);
|
_result.ReRoutes[i].DownstreamScheme.ShouldBe(expected.ReRoutes[i].DownstreamScheme);
|
||||||
//todo -- add more!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user