mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:42:50 +08:00
Add ability to specify scheme of ServiceProviderConfiguration
This commit is contained in:
parent
347ea7280c
commit
cd3dc00c1a
@ -9,7 +9,7 @@
|
|||||||
{
|
{
|
||||||
return new ConsulClient(c =>
|
return new ConsulClient(c =>
|
||||||
{
|
{
|
||||||
c.Address = new Uri($"http://{config.Host}:{config.Port}");
|
c.Address = new Uri($"{config.Scheme}://{config.Host}:{config.Port}");
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(config?.Token))
|
if (!string.IsNullOrEmpty(config?.Token))
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
var consulFactory = provider.GetService<IConsulClientFactory>();
|
var consulFactory = provider.GetService<IConsulClientFactory>();
|
||||||
|
|
||||||
var consulRegistryConfiguration = new ConsulRegistryConfiguration(config.Host, config.Port, reRoute.ServiceName, config.Token);
|
var consulRegistryConfiguration = new ConsulRegistryConfiguration(config.Scheme, config.Host, config.Port, reRoute.ServiceName, config.Token);
|
||||||
|
|
||||||
var consulServiceDiscoveryProvider = new Consul(consulRegistryConfiguration, factory, consulFactory);
|
var consulServiceDiscoveryProvider = new Consul(consulRegistryConfiguration, factory, consulFactory);
|
||||||
|
|
||||||
|
@ -2,15 +2,17 @@
|
|||||||
{
|
{
|
||||||
public class ConsulRegistryConfiguration
|
public class ConsulRegistryConfiguration
|
||||||
{
|
{
|
||||||
public ConsulRegistryConfiguration(string host, int port, string keyOfServiceInConsul, string token)
|
public ConsulRegistryConfiguration(string scheme, string host, int port, string keyOfServiceInConsul, string token)
|
||||||
{
|
{
|
||||||
Host = string.IsNullOrEmpty(host) ? "localhost" : host;
|
Host = string.IsNullOrEmpty(host) ? "localhost" : host;
|
||||||
Port = port > 0 ? port : 8500;
|
Port = port > 0 ? port : 8500;
|
||||||
|
Scheme = string.IsNullOrEmpty(scheme) ? "http" : scheme;
|
||||||
KeyOfServiceInConsul = keyOfServiceInConsul;
|
KeyOfServiceInConsul = keyOfServiceInConsul;
|
||||||
Token = token;
|
Token = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string KeyOfServiceInConsul { get; }
|
public string KeyOfServiceInConsul { get; }
|
||||||
|
public string Scheme { get; }
|
||||||
public string Host { get; }
|
public string Host { get; }
|
||||||
public int Port { get; }
|
public int Port { get; }
|
||||||
public string Token { get; }
|
public string Token { get; }
|
||||||
|
@ -2,6 +2,7 @@ namespace Ocelot.Configuration.Builder
|
|||||||
{
|
{
|
||||||
public class ServiceProviderConfigurationBuilder
|
public class ServiceProviderConfigurationBuilder
|
||||||
{
|
{
|
||||||
|
private string _serviceDiscoveryProviderScheme;
|
||||||
private string _serviceDiscoveryProviderHost;
|
private string _serviceDiscoveryProviderHost;
|
||||||
private int _serviceDiscoveryProviderPort;
|
private int _serviceDiscoveryProviderPort;
|
||||||
private string _type;
|
private string _type;
|
||||||
@ -10,6 +11,12 @@ namespace Ocelot.Configuration.Builder
|
|||||||
private int _pollingInterval;
|
private int _pollingInterval;
|
||||||
private string _namespace;
|
private string _namespace;
|
||||||
|
|
||||||
|
public ServiceProviderConfigurationBuilder WithScheme(string serviceDiscoveryProviderScheme)
|
||||||
|
{
|
||||||
|
_serviceDiscoveryProviderScheme = serviceDiscoveryProviderScheme;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ServiceProviderConfigurationBuilder WithHost(string serviceDiscoveryProviderHost)
|
public ServiceProviderConfigurationBuilder WithHost(string serviceDiscoveryProviderHost)
|
||||||
{
|
{
|
||||||
_serviceDiscoveryProviderHost = serviceDiscoveryProviderHost;
|
_serviceDiscoveryProviderHost = serviceDiscoveryProviderHost;
|
||||||
@ -54,7 +61,7 @@ namespace Ocelot.Configuration.Builder
|
|||||||
|
|
||||||
public ServiceProviderConfiguration Build()
|
public ServiceProviderConfiguration Build()
|
||||||
{
|
{
|
||||||
return new ServiceProviderConfiguration(_type, _serviceDiscoveryProviderHost, _serviceDiscoveryProviderPort, _token, _configurationKey, _pollingInterval, _namespace);
|
return new ServiceProviderConfiguration(_type, _serviceDiscoveryProviderScheme, _serviceDiscoveryProviderHost, _serviceDiscoveryProviderPort, _token, _configurationKey, _pollingInterval, _namespace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ namespace Ocelot.Configuration.Creator
|
|||||||
public ServiceProviderConfiguration Create(FileGlobalConfiguration globalConfiguration)
|
public ServiceProviderConfiguration Create(FileGlobalConfiguration globalConfiguration)
|
||||||
{
|
{
|
||||||
var port = globalConfiguration?.ServiceDiscoveryProvider?.Port ?? 0;
|
var port = globalConfiguration?.ServiceDiscoveryProvider?.Port ?? 0;
|
||||||
|
var scheme = globalConfiguration?.ServiceDiscoveryProvider?.Scheme ?? "http";
|
||||||
var host = globalConfiguration?.ServiceDiscoveryProvider?.Host ?? "localhost";
|
var host = globalConfiguration?.ServiceDiscoveryProvider?.Host ?? "localhost";
|
||||||
var type = !string.IsNullOrEmpty(globalConfiguration?.ServiceDiscoveryProvider?.Type)
|
var type = !string.IsNullOrEmpty(globalConfiguration?.ServiceDiscoveryProvider?.Type)
|
||||||
? globalConfiguration?.ServiceDiscoveryProvider?.Type
|
? globalConfiguration?.ServiceDiscoveryProvider?.Type
|
||||||
@ -16,6 +17,7 @@ namespace Ocelot.Configuration.Creator
|
|||||||
var k8snamespace = globalConfiguration?.ServiceDiscoveryProvider?.Namespace ?? string.Empty;
|
var k8snamespace = globalConfiguration?.ServiceDiscoveryProvider?.Namespace ?? string.Empty;
|
||||||
|
|
||||||
return new ServiceProviderConfigurationBuilder()
|
return new ServiceProviderConfigurationBuilder()
|
||||||
|
.WithScheme(scheme)
|
||||||
.WithHost(host)
|
.WithHost(host)
|
||||||
.WithPort(port)
|
.WithPort(port)
|
||||||
.WithType(type)
|
.WithType(type)
|
||||||
|
@ -2,6 +2,7 @@ namespace Ocelot.Configuration.File
|
|||||||
{
|
{
|
||||||
public class FileServiceDiscoveryProvider
|
public class FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
public string Scheme { get; set; }
|
||||||
public string Host { get; set; }
|
public string Host { get; set; }
|
||||||
public int Port { get; set; }
|
public int Port { get; set; }
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
{
|
{
|
||||||
public class ServiceProviderConfiguration
|
public class ServiceProviderConfiguration
|
||||||
{
|
{
|
||||||
public ServiceProviderConfiguration(string type, string host, int port, string token, string configurationKey, int pollingInterval, string @namespace = "")
|
public ServiceProviderConfiguration(string type, string scheme, string host, int port, string token, string configurationKey, int pollingInterval, string @namespace = "")
|
||||||
{
|
{
|
||||||
ConfigurationKey = configurationKey;
|
ConfigurationKey = configurationKey;
|
||||||
|
Scheme = scheme;
|
||||||
Host = host;
|
Host = host;
|
||||||
Port = port;
|
Port = port;
|
||||||
Token = token;
|
Token = token;
|
||||||
@ -13,6 +14,8 @@
|
|||||||
Namespace = @namespace;
|
Namespace = @namespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Scheme { get; }
|
||||||
|
|
||||||
public string Host { get; }
|
public string Host { get; }
|
||||||
|
|
||||||
public int Port { get; }
|
public int Port { get; }
|
||||||
|
@ -24,6 +24,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Type = "consul",
|
Type = "consul",
|
||||||
Port = 8500
|
Port = 8500
|
||||||
@ -66,6 +67,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Type = "consul",
|
Type = "consul",
|
||||||
Port = 8500
|
Port = 8500
|
||||||
|
@ -59,6 +59,7 @@ namespace Ocelot.AcceptanceTests
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
@ -91,6 +92,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
@ -123,6 +125,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
@ -152,6 +155,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
@ -184,6 +188,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
@ -214,6 +219,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
@ -274,6 +280,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
},
|
},
|
||||||
@ -295,6 +302,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
|
@ -83,6 +83,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort,
|
Port = consulPort,
|
||||||
Type = "consul"
|
Type = "consul"
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
@ -137,6 +138,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
@ -180,6 +182,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
},
|
},
|
||||||
@ -243,6 +246,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
},
|
},
|
||||||
@ -302,6 +306,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort,
|
Port = consulPort,
|
||||||
Token = token
|
Token = token
|
||||||
@ -372,6 +377,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
@ -437,6 +443,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "http",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort,
|
Port = consulPort,
|
||||||
Type = "PollConsul",
|
Type = "PollConsul",
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider()
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = consulPort
|
Port = consulPort
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,7 @@ namespace Ocelot.IntegrationTests
|
|||||||
RequestIdKey = "RequestId",
|
RequestIdKey = "RequestId",
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "127.0.0.1",
|
Host = "127.0.0.1",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -660,6 +661,7 @@ namespace Ocelot.IntegrationTests
|
|||||||
var response = JsonConvert.DeserializeObject<FileConfiguration>(_response.Content.ReadAsStringAsync().Result);
|
var response = JsonConvert.DeserializeObject<FileConfiguration>(_response.Content.ReadAsStringAsync().Result);
|
||||||
|
|
||||||
response.GlobalConfiguration.RequestIdKey.ShouldBe(expecteds.GlobalConfiguration.RequestIdKey);
|
response.GlobalConfiguration.RequestIdKey.ShouldBe(expecteds.GlobalConfiguration.RequestIdKey);
|
||||||
|
response.GlobalConfiguration.ServiceDiscoveryProvider.Scheme.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Scheme);
|
||||||
response.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Host);
|
response.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Host);
|
||||||
response.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Port);
|
response.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Port);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
GlobalConfiguration = new FileGlobalConfiguration()
|
GlobalConfiguration = new FileGlobalConfiguration()
|
||||||
};
|
};
|
||||||
_reRoutes = new List<ReRoute>();
|
_reRoutes = new List<ReRoute>();
|
||||||
_spc = new ServiceProviderConfiguration("", "", 1, "", "", 1);
|
_spc = new ServiceProviderConfiguration("", "", "", 1, "", "", 1);
|
||||||
_lbo = new LoadBalancerOptionsBuilder().Build();
|
_lbo = new LoadBalancerOptionsBuilder().Build();
|
||||||
_qoso = new QoSOptions(1, 1, 1, "");
|
_qoso = new QoSOptions(1, 1, 1, "");
|
||||||
_hho = new HttpHandlerOptionsBuilder().Build();
|
_hho = new HttpHandlerOptionsBuilder().Build();
|
||||||
|
@ -139,6 +139,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
private void ThenTheConfigurationIsStoredAs(FileConfiguration expecteds)
|
private void ThenTheConfigurationIsStoredAs(FileConfiguration expecteds)
|
||||||
{
|
{
|
||||||
_result.GlobalConfiguration.RequestIdKey.ShouldBe(expecteds.GlobalConfiguration.RequestIdKey);
|
_result.GlobalConfiguration.RequestIdKey.ShouldBe(expecteds.GlobalConfiguration.RequestIdKey);
|
||||||
|
_result.GlobalConfiguration.ServiceDiscoveryProvider.Scheme.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Scheme);
|
||||||
_result.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Host);
|
_result.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Host);
|
||||||
_result.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Port);
|
_result.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Port);
|
||||||
|
|
||||||
@ -196,6 +197,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
private void ThenTheFollowingIsReturned(FileConfiguration expecteds)
|
private void ThenTheFollowingIsReturned(FileConfiguration expecteds)
|
||||||
{
|
{
|
||||||
_result.GlobalConfiguration.RequestIdKey.ShouldBe(expecteds.GlobalConfiguration.RequestIdKey);
|
_result.GlobalConfiguration.RequestIdKey.ShouldBe(expecteds.GlobalConfiguration.RequestIdKey);
|
||||||
|
_result.GlobalConfiguration.ServiceDiscoveryProvider.Scheme.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Scheme);
|
||||||
_result.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Host);
|
_result.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Host);
|
||||||
_result.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Port);
|
_result.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(expecteds.GlobalConfiguration.ServiceDiscoveryProvider.Port);
|
||||||
|
|
||||||
@ -243,6 +245,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Port = 198,
|
Port = 198,
|
||||||
Host = "blah"
|
Host = "blah"
|
||||||
}
|
}
|
||||||
@ -278,6 +281,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Port = 198,
|
Port = 198,
|
||||||
Host = "blah"
|
Host = "blah"
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "127.0.0.1",
|
Host = "127.0.0.1",
|
||||||
Port = 1234,
|
Port = 1234,
|
||||||
Type = "ServiceFabric",
|
Type = "ServiceFabric",
|
||||||
@ -36,6 +37,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
};
|
};
|
||||||
|
|
||||||
var expected = new ServiceProviderConfigurationBuilder()
|
var expected = new ServiceProviderConfigurationBuilder()
|
||||||
|
.WithScheme("https")
|
||||||
.WithHost("127.0.0.1")
|
.WithHost("127.0.0.1")
|
||||||
.WithPort(1234)
|
.WithPort(1234)
|
||||||
.WithType("ServiceFabric")
|
.WithType("ServiceFabric")
|
||||||
@ -62,6 +64,7 @@ namespace Ocelot.UnitTests.Configuration
|
|||||||
|
|
||||||
private void ThenTheConfigIs(ServiceProviderConfiguration expected)
|
private void ThenTheConfigIs(ServiceProviderConfiguration expected)
|
||||||
{
|
{
|
||||||
|
_result.Scheme.ShouldBe(expected.Scheme);
|
||||||
_result.Host.ShouldBe(expected.Host);
|
_result.Host.ShouldBe(expected.Host);
|
||||||
_result.Port.ShouldBe(expected.Port);
|
_result.Port.ShouldBe(expected.Port);
|
||||||
_result.Token.ShouldBe(expected.Token);
|
_result.Token.ShouldBe(expected.Token);
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Type = "ServiceFabric",
|
Type = "ServiceFabric",
|
||||||
Port = 8500
|
Port = 8500
|
||||||
@ -90,6 +91,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Type = "FakeServiceDiscoveryProvider",
|
Type = "FakeServiceDiscoveryProvider",
|
||||||
Port = 8500
|
Port = 8500
|
||||||
@ -113,6 +115,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Type = "FakeServiceDiscoveryProvider",
|
Type = "FakeServiceDiscoveryProvider",
|
||||||
Port = 8500
|
Port = 8500
|
||||||
@ -147,6 +150,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Type = "FakeServiceDiscoveryProvider",
|
Type = "FakeServiceDiscoveryProvider",
|
||||||
Port = 8500
|
Port = 8500
|
||||||
@ -171,6 +175,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Type = "FakeServiceDiscoveryProvider",
|
Type = "FakeServiceDiscoveryProvider",
|
||||||
Port = 8500
|
Port = 8500
|
||||||
@ -206,6 +211,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Type = "consul",
|
Type = "consul",
|
||||||
Port = 8500
|
Port = 8500
|
||||||
@ -1197,6 +1203,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Type = "servicefabric",
|
Type = "servicefabric",
|
||||||
Host = "localhost",
|
Host = "localhost",
|
||||||
Port = 1234
|
Port = 1234
|
||||||
|
@ -244,6 +244,7 @@
|
|||||||
{
|
{
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Port = 198,
|
Port = 198,
|
||||||
Host = "blah"
|
Host = "blah"
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
private readonly string _serviceName;
|
private readonly string _serviceName;
|
||||||
private readonly int _port;
|
private readonly int _port;
|
||||||
private readonly string _consulHost;
|
private readonly string _consulHost;
|
||||||
|
private readonly string _consulScheme;
|
||||||
private readonly string _fakeConsulServiceDiscoveryUrl;
|
private readonly string _fakeConsulServiceDiscoveryUrl;
|
||||||
private List<Service> _services;
|
private List<Service> _services;
|
||||||
private readonly Mock<IOcelotLoggerFactory> _factory;
|
private readonly Mock<IOcelotLoggerFactory> _factory;
|
||||||
@ -37,6 +38,7 @@
|
|||||||
_serviceName = "test";
|
_serviceName = "test";
|
||||||
_port = 8500;
|
_port = 8500;
|
||||||
_consulHost = "localhost";
|
_consulHost = "localhost";
|
||||||
|
_consulScheme = "https";
|
||||||
_fakeConsulServiceDiscoveryUrl = $"http://{_consulHost}:{_port}";
|
_fakeConsulServiceDiscoveryUrl = $"http://{_consulHost}:{_port}";
|
||||||
_serviceEntries = new List<ServiceEntry>();
|
_serviceEntries = new List<ServiceEntry>();
|
||||||
_factory = new Mock<IOcelotLoggerFactory>();
|
_factory = new Mock<IOcelotLoggerFactory>();
|
||||||
@ -44,7 +46,7 @@
|
|||||||
_logger = new Mock<IOcelotLogger>();
|
_logger = new Mock<IOcelotLogger>();
|
||||||
_factory.Setup(x => x.CreateLogger<Consul>()).Returns(_logger.Object);
|
_factory.Setup(x => x.CreateLogger<Consul>()).Returns(_logger.Object);
|
||||||
_factory.Setup(x => x.CreateLogger<PollConsul>()).Returns(_logger.Object);
|
_factory.Setup(x => x.CreateLogger<PollConsul>()).Returns(_logger.Object);
|
||||||
var config = new ConsulRegistryConfiguration(_consulHost, _port, _serviceName, null);
|
var config = new ConsulRegistryConfiguration(_consulScheme, _consulHost, _port, _serviceName, null);
|
||||||
_provider = new Consul(config, _factory.Object, _clientFactory);
|
_provider = new Consul(config, _factory.Object, _clientFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +76,7 @@
|
|||||||
public void should_use_token()
|
public void should_use_token()
|
||||||
{
|
{
|
||||||
var token = "test token";
|
var token = "test token";
|
||||||
var config = new ConsulRegistryConfiguration(_consulHost, _port, _serviceName, token);
|
var config = new ConsulRegistryConfiguration(_consulScheme, _consulHost, _port, _serviceName, token);
|
||||||
_provider = new Consul(config, _factory.Object, _clientFactory);
|
_provider = new Consul(config, _factory.Object, _clientFactory);
|
||||||
|
|
||||||
var serviceEntryOne = new ServiceEntry()
|
var serviceEntryOne = new ServiceEntry()
|
||||||
|
@ -35,7 +35,7 @@ namespace Ocelot.UnitTests.Consul
|
|||||||
.WithServiceName("")
|
.WithServiceName("")
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
var provider = ConsulProviderFactory.Get(_provider, new ServiceProviderConfiguration("", "", 1, "", "", 1), reRoute);
|
var provider = ConsulProviderFactory.Get(_provider, new ServiceProviderConfiguration("", "", "", 1, "", "", 1), reRoute);
|
||||||
provider.ShouldBeOfType<Consul>();
|
provider.ShouldBeOfType<Consul>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@
|
|||||||
},
|
},
|
||||||
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
ServiceDiscoveryProvider = new FileServiceDiscoveryProvider
|
||||||
{
|
{
|
||||||
|
Scheme = "https",
|
||||||
Host = "Host",
|
Host = "Host",
|
||||||
Port = 80,
|
Port = 80,
|
||||||
Type = "Type"
|
Type = "Type"
|
||||||
@ -277,6 +278,7 @@
|
|||||||
fc.GlobalConfiguration.RateLimitOptions.QuotaExceededMessage.ShouldBe(_globalConfig.GlobalConfiguration.RateLimitOptions.QuotaExceededMessage);
|
fc.GlobalConfiguration.RateLimitOptions.QuotaExceededMessage.ShouldBe(_globalConfig.GlobalConfiguration.RateLimitOptions.QuotaExceededMessage);
|
||||||
fc.GlobalConfiguration.RateLimitOptions.RateLimitCounterPrefix.ShouldBe(_globalConfig.GlobalConfiguration.RateLimitOptions.RateLimitCounterPrefix);
|
fc.GlobalConfiguration.RateLimitOptions.RateLimitCounterPrefix.ShouldBe(_globalConfig.GlobalConfiguration.RateLimitOptions.RateLimitCounterPrefix);
|
||||||
fc.GlobalConfiguration.RequestIdKey.ShouldBe(_globalConfig.GlobalConfiguration.RequestIdKey);
|
fc.GlobalConfiguration.RequestIdKey.ShouldBe(_globalConfig.GlobalConfiguration.RequestIdKey);
|
||||||
|
fc.GlobalConfiguration.ServiceDiscoveryProvider.Scheme.ShouldBe(_globalConfig.GlobalConfiguration.ServiceDiscoveryProvider.Scheme);
|
||||||
fc.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(_globalConfig.GlobalConfiguration.ServiceDiscoveryProvider.Host);
|
fc.GlobalConfiguration.ServiceDiscoveryProvider.Host.ShouldBe(_globalConfig.GlobalConfiguration.ServiceDiscoveryProvider.Host);
|
||||||
fc.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(_globalConfig.GlobalConfiguration.ServiceDiscoveryProvider.Port);
|
fc.GlobalConfiguration.ServiceDiscoveryProvider.Port.ShouldBe(_globalConfig.GlobalConfiguration.ServiceDiscoveryProvider.Port);
|
||||||
fc.GlobalConfiguration.ServiceDiscoveryProvider.Type.ShouldBe(_globalConfig.GlobalConfiguration.ServiceDiscoveryProvider.Type);
|
fc.GlobalConfiguration.ServiceDiscoveryProvider.Type.ShouldBe(_globalConfig.GlobalConfiguration.ServiceDiscoveryProvider.Type);
|
||||||
|
@ -54,7 +54,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_downstream_route_finder_when_not_dynamic_re_route_and_service_discovery_on()
|
public void should_return_downstream_route_finder_when_not_dynamic_re_route_and_service_discovery_on()
|
||||||
{
|
{
|
||||||
var spConfig = new ServiceProviderConfigurationBuilder().WithHost("test").WithPort(50).WithType("test").Build();
|
var spConfig = new ServiceProviderConfigurationBuilder().WithScheme("http").WithHost("test").WithPort(50).WithType("test").Build();
|
||||||
var reRoutes = new List<ReRoute>
|
var reRoutes = new List<ReRoute>
|
||||||
{
|
{
|
||||||
new ReRouteBuilder().WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithOriginalValue("woot").Build()).Build()
|
new ReRouteBuilder().WithUpstreamPathTemplate(new UpstreamPathTemplateBuilder().WithOriginalValue("woot").Build()).Build()
|
||||||
@ -66,10 +66,22 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
|||||||
.BDDfy();
|
.BDDfy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void should_return_downstream_route_finder_as_no_service_discovery_given_no_scheme()
|
||||||
|
{
|
||||||
|
var spConfig = new ServiceProviderConfigurationBuilder().WithScheme("").WithHost("test").WithPort(50).Build();
|
||||||
|
var reRoutes = new List<ReRoute>();
|
||||||
|
|
||||||
|
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||||
|
.When(_ => WhenIGet())
|
||||||
|
.Then(_ => ThenTheResultShouldBe<DownstreamRouteFinder>())
|
||||||
|
.BDDfy();
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_downstream_route_finder_as_no_service_discovery_given_no_host()
|
public void should_return_downstream_route_finder_as_no_service_discovery_given_no_host()
|
||||||
{
|
{
|
||||||
var spConfig = new ServiceProviderConfigurationBuilder().WithHost("").WithPort(50).Build();
|
var spConfig = new ServiceProviderConfigurationBuilder().WithScheme("http").WithHost("").WithPort(50).Build();
|
||||||
var reRoutes = new List<ReRoute>();
|
var reRoutes = new List<ReRoute>();
|
||||||
|
|
||||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||||
@ -81,7 +93,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_downstream_route_finder_given_no_service_discovery_port()
|
public void should_return_downstream_route_finder_given_no_service_discovery_port()
|
||||||
{
|
{
|
||||||
var spConfig = new ServiceProviderConfigurationBuilder().WithHost("localhost").WithPort(0).Build();
|
var spConfig = new ServiceProviderConfigurationBuilder().WithScheme("http").WithHost("localhost").WithPort(0).Build();
|
||||||
var reRoutes = new List<ReRoute>();
|
var reRoutes = new List<ReRoute>();
|
||||||
|
|
||||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||||
@ -93,7 +105,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_downstream_route_finder_given_no_service_discovery_type()
|
public void should_return_downstream_route_finder_given_no_service_discovery_type()
|
||||||
{
|
{
|
||||||
var spConfig = new ServiceProviderConfigurationBuilder().WithHost("localhost").WithPort(50).WithType("").Build();
|
var spConfig = new ServiceProviderConfigurationBuilder().WithScheme("http").WithHost("localhost").WithPort(50).WithType("").Build();
|
||||||
var reRoutes = new List<ReRoute>();
|
var reRoutes = new List<ReRoute>();
|
||||||
|
|
||||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||||
@ -105,7 +117,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_downstream_route_creator()
|
public void should_return_downstream_route_creator()
|
||||||
{
|
{
|
||||||
var spConfig = new ServiceProviderConfigurationBuilder().WithHost("test").WithPort(50).WithType("test").Build();
|
var spConfig = new ServiceProviderConfigurationBuilder().WithScheme("http").WithHost("test").WithPort(50).WithType("test").Build();
|
||||||
var reRoutes = new List<ReRoute>();
|
var reRoutes = new List<ReRoute>();
|
||||||
|
|
||||||
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
this.Given(_ => GivenTheReRoutes(reRoutes, spConfig))
|
||||||
@ -117,7 +129,7 @@ namespace Ocelot.UnitTests.DownstreamRouteFinder
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void should_return_downstream_route_creator_with_dynamic_re_route()
|
public void should_return_downstream_route_creator_with_dynamic_re_route()
|
||||||
{
|
{
|
||||||
var spConfig = new ServiceProviderConfigurationBuilder().WithHost("test").WithPort(50).WithType("test").Build();
|
var spConfig = new ServiceProviderConfigurationBuilder().WithScheme("http").WithHost("test").WithPort(50).WithType("test").Build();
|
||||||
var reRoutes = new List<ReRoute>
|
var reRoutes = new List<ReRoute>
|
||||||
{
|
{
|
||||||
new ReRouteBuilder().Build()
|
new ReRouteBuilder().Build()
|
||||||
|
@ -26,7 +26,7 @@ namespace Ocelot.UnitTests.LoadBalancer
|
|||||||
{
|
{
|
||||||
_factory = new Mock<ILoadBalancerFactory>();
|
_factory = new Mock<ILoadBalancerFactory>();
|
||||||
_loadBalancerHouse = new LoadBalancerHouse(_factory.Object);
|
_loadBalancerHouse = new LoadBalancerHouse(_factory.Object);
|
||||||
_serviceProviderConfig = new ServiceProviderConfiguration("myType", "myHost", 123, string.Empty, "configKey", 0);
|
_serviceProviderConfig = new ServiceProviderConfiguration("myType", "myScheme", "myHost", 123, string.Empty, "configKey", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user