mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:42:50 +08:00
feat : add kube provider unittest
This commit is contained in:
parent
b1cd23459e
commit
1f5c71b45c
35
test/Ocelot.UnitTests/Kubernetes/KubeProviderFactoryTests.cs
Normal file
35
test/Ocelot.UnitTests/Kubernetes/KubeProviderFactoryTests.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Moq;
|
||||||
|
using Ocelot.Configuration;
|
||||||
|
using Ocelot.Logging;
|
||||||
|
using Ocelot.Provider.Kubernetes;
|
||||||
|
using Shouldly;
|
||||||
|
using System;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Ocelot.UnitTests.Kubernetes
|
||||||
|
{
|
||||||
|
public class KubeProviderFactoryTests
|
||||||
|
{
|
||||||
|
private readonly IServiceProvider _provider;
|
||||||
|
|
||||||
|
public KubeProviderFactoryTests()
|
||||||
|
{
|
||||||
|
var services = new ServiceCollection();
|
||||||
|
var loggerFactory = new Mock<IOcelotLoggerFactory>();
|
||||||
|
var logger = new Mock<IOcelotLogger>();
|
||||||
|
loggerFactory.Setup(x => x.CreateLogger<Kube>()).Returns(logger.Object);
|
||||||
|
var kubeFactory = new Mock<IKubeApiClientFactory>();
|
||||||
|
services.AddSingleton(kubeFactory.Object);
|
||||||
|
services.AddSingleton(loggerFactory.Object);
|
||||||
|
_provider = services.BuildServiceProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void should_return_KubeServiceDiscoveryProvider()
|
||||||
|
{
|
||||||
|
var provider = KubernetesProviderFactory.Get(_provider, new ServiceProviderConfiguration("kube", "localhost", 443, "", "", 1,"dev"), "");
|
||||||
|
provider.ShouldBeOfType<Kube>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using TestStack.BDDfy;
|
using TestStack.BDDfy;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
@ -0,0 +1,70 @@
|
|||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Hosting.Internal;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Ocelot.DependencyInjection;
|
||||||
|
using Ocelot.Provider.Kubernetes;
|
||||||
|
using Shouldly;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using TestStack.BDDfy;
|
||||||
|
using Xunit;
|
||||||
|
|
||||||
|
namespace Ocelot.UnitTests.Kubernetes
|
||||||
|
{
|
||||||
|
public class OcelotBuilderExtensionsTests
|
||||||
|
{
|
||||||
|
private readonly IServiceCollection _services;
|
||||||
|
private IServiceProvider _serviceProvider;
|
||||||
|
private readonly IConfiguration _configRoot;
|
||||||
|
private IOcelotBuilder _ocelotBuilder;
|
||||||
|
private Exception _ex;
|
||||||
|
|
||||||
|
public OcelotBuilderExtensionsTests()
|
||||||
|
{
|
||||||
|
_configRoot = new ConfigurationRoot(new List<IConfigurationProvider>());
|
||||||
|
_services = new ServiceCollection();
|
||||||
|
_services.AddSingleton<IHostingEnvironment, HostingEnvironment>();
|
||||||
|
_services.AddSingleton(_configRoot);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void should_set_up_kubernetes()
|
||||||
|
{
|
||||||
|
this.Given(x => WhenISetUpOcelotServices())
|
||||||
|
.When(x => WhenISetUpKubernetes())
|
||||||
|
.Then(x => ThenAnExceptionIsntThrown())
|
||||||
|
.BDDfy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WhenISetUpOcelotServices()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ocelotBuilder = _services.AddOcelot(_configRoot);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_ex = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WhenISetUpKubernetes()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ocelotBuilder.AddKubernetes();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_ex = e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ThenAnExceptionIsntThrown()
|
||||||
|
{
|
||||||
|
_ex.ShouldBeNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user