Skip to content

Commit ddfe948

Browse files
committed
Add tests for Spring Boot Admin
1 parent 35ba024 commit ddfe948

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/Management/test/Endpoint.Test/SpringBootAdminClient/ServiceCollectionExtensionsTest.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,21 @@
77
using Microsoft.Extensions.Configuration;
88
using Microsoft.Extensions.DependencyInjection;
99
using Microsoft.Extensions.Hosting;
10-
using Steeltoe.Common;
11-
using Steeltoe.Common.Net;
1210
using Steeltoe.Management.Endpoint.SpringBootAdminClient;
1311

1412
namespace Steeltoe.Management.Endpoint.Test.SpringBootAdminClient;
1513

1614
public sealed class ServiceCollectionExtensionsTest
1715
{
1816
[Fact]
19-
public async Task AddSpringBootAdminClient_AddsHostedService()
17+
public async Task Registers_dependent_services()
2018
{
21-
IConfiguration configuration = new ConfigurationBuilder().Build();
22-
2319
var services = new ServiceCollection();
24-
services.AddSingleton(configuration);
20+
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
2521
services.AddSingleton<IServer, TestServer>();
26-
services.AddLogging();
2722
services.AddSpringBootAdminClient();
2823
await using ServiceProvider serviceProvider = services.BuildServiceProvider(true);
2924

30-
serviceProvider.GetService<IApplicationInstanceInfo>().Should().NotBeNull();
31-
serviceProvider.GetService<InetUtils>().Should().NotBeNull();
32-
serviceProvider.GetService<TimeProvider>().Should().NotBeNull();
33-
serviceProvider.GetService<IDomainNameResolver>().Should().NotBeNull();
34-
serviceProvider.GetService<AppUrlCalculator>().Should().NotBeNull();
35-
serviceProvider.GetService<SpringBootAdminRefreshRunner>().Should().NotBeNull();
3625
serviceProvider.GetServices<IHostedService>().OfType<SpringBootAdminClientHostedService>().Should().ContainSingle();
3726
}
3827
}

src/Management/test/Endpoint.Test/SpringBootAdminClient/SpringBootAdminRefreshRunnerTest.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,31 @@ public sealed class SpringBootAdminRefreshRunnerTest
2626
private const string CurrentTime = "2021-03-31T23:57:53.896653Z";
2727
private static readonly string CurrentAppName = Assembly.GetEntryAssembly()!.GetName().Name!;
2828

29+
[Fact]
30+
public async Task Configures_default_settings()
31+
{
32+
var services = new ServiceCollection();
33+
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
34+
services.AddSpringBootAdminClient();
35+
await using ServiceProvider serviceProvider = services.BuildServiceProvider(true);
36+
37+
SpringBootAdminClientOptions options = serviceProvider.GetRequiredService<IOptions<SpringBootAdminClientOptions>>().Value;
38+
39+
options.Url.Should().BeNull();
40+
options.ApplicationName.Should().BeNull();
41+
options.BaseUrl.Should().BeNull();
42+
options.BaseScheme.Should().BeNull();
43+
options.BaseHost.Should().BeNull();
44+
options.BasePort.Should().BeNull();
45+
options.BasePath.Should().BeNull();
46+
options.UseNetworkInterfaces.Should().BeFalse();
47+
options.PreferIPAddress.Should().BeFalse();
48+
options.ValidateCertificates.Should().BeTrue();
49+
options.ConnectionTimeout.Should().Be(5.Seconds());
50+
options.RefreshInterval.Should().Be(15.Seconds());
51+
options.Metadata.Should().BeEmpty();
52+
}
53+
2954
[Fact]
3055
public async Task BindsConfiguration()
3156
{

0 commit comments

Comments
 (0)