Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a86c314
Refactor tests for dbmigrations endpoint
bart-vmware May 23, 2025
db6b58c
Refactor tests for env endpoint
bart-vmware May 23, 2025
a93fc23
Add internal file system abstraction for testability of disk space co…
bart-vmware May 26, 2025
f738517
Order health check results in descending status
bart-vmware May 27, 2025
3f8168e
Simplify test health contributors (single purpose)
bart-vmware May 27, 2025
62f7bda
Refactor tests for health endpoint
bart-vmware May 27, 2025
d3b4af7
Refactor tests for health contributors, move availability contributor…
bart-vmware May 28, 2025
6179dc1
Move HttpExchanges into MemoryDumps category
bart-vmware May 28, 2025
4660408
Refactor tests for heapdump endpoint
bart-vmware May 28, 2025
a223adc
Refactor tests for threaddump endpoint
bart-vmware May 28, 2025
2f411de
Refactor tests for httpexchanges endpoint
bart-vmware May 30, 2025
e0b00bd
Reduce pressure when running all tests locally, so that DiagnosticObs…
bart-vmware Jun 3, 2025
22406b1
Refactor tests for hypermedia endpoint
bart-vmware Jun 2, 2025
d8039dd
Refactor tests for info endpoint
bart-vmware Jun 3, 2025
0ce2a7c
Refactor tests for loggers endpoint
bart-vmware Jun 4, 2025
885b467
Refactor tests for refresh endpoint
bart-vmware Jun 5, 2025
23ae69c
Refactor tests for mappings endpoint
bart-vmware Jun 5, 2025
7d6f32a
Refactor tests for beans endpoint
bart-vmware Jun 5, 2025
529c198
Revise tests for dependent services: get middleware instance to ensur…
bart-vmware Jun 6, 2025
3e0e2f7
Simplify tests for options: there's no added value in using host buil…
bart-vmware Jun 6, 2025
831514c
Cleanup tests for management/endpoint options - Fixed: allow clearing…
bart-vmware Jun 6, 2025
9572f09
Remove unused types
bart-vmware Jun 6, 2025
9342e36
Add tests for Spring Boot Admin
bart-vmware Jun 6, 2025
c38a2d0
Move content negotation tests for SBA
bart-vmware Jun 10, 2025
e070a2a
Refactor tests for all actuators
bart-vmware Jun 10, 2025
6bef783
Adapt configuration key names to .NET naming convention, inline const…
bart-vmware Jun 10, 2025
f360115
Rename/inline test type
bart-vmware Jun 10, 2025
040a2c9
Refactor tests for cloudfoundryapplication endpoint
bart-vmware Jun 12, 2025
d91dee4
Do not hide empty sources in env endpoint for Spring Boot compatibility
bart-vmware Jun 16, 2025
fbdf746
Fix line endings in *.git.properties files
bart-vmware Jun 16, 2025
662a92e
Centralize "appsettings.json" constant
bart-vmware Jun 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Enable running shell scripts from bash on Windows
*.git.properties eol=lf
64 changes: 50 additions & 14 deletions src/Common/src/Common/HealthChecks/HealthAggregator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.Collections.Concurrent;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Steeltoe.Common.CasingConventions;
using Steeltoe.Common.Extensions;
using MicrosoftHealthCheckResult = Microsoft.Extensions.Diagnostics.HealthChecks.HealthCheckResult;
using MicrosoftHealthStatus = Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus;
Expand Down Expand Up @@ -112,22 +111,14 @@ private static async Task<SteeltoeHealthCheckResult> RunMicrosoftHealthCheckAsyn
IHealthCheck check = registration.Factory(serviceProvider);
MicrosoftHealthCheckResult result = await check.CheckHealthAsync(context, cancellationToken);

SteeltoeHealthStatus status = ToHealthStatus(result.Status);
healthCheckResult.Status = status; // Only used for aggregate, doesn't get reported
healthCheckResult.Status = ToHealthStatus(result.Status);
healthCheckResult.Description = result.Description;

foreach ((string key, object value) in result.Data)
{
healthCheckResult.Details[key] = value;
}

healthCheckResult.Details["status"] = status.ToSnakeCaseString(SnakeCaseStyle.AllCaps);

if (result.Description != null)
{
healthCheckResult.Details.Add("description", result.Description);
}

if (result.Exception != null && !string.IsNullOrEmpty(result.Exception.Message))
{
healthCheckResult.Details.Add("error", result.Exception.Message);
Expand Down Expand Up @@ -172,16 +163,61 @@ private static string GetKey(ConcurrentBag<string> keys, string key)

private static SteeltoeHealthCheckResult AddChecksSetStatus(SteeltoeHealthCheckResult result, IDictionary<string, SteeltoeHealthCheckResult> healthChecks)
{
foreach (KeyValuePair<string, SteeltoeHealthCheckResult> healthCheck in healthChecks)
var orderedCheckResults = new SortedDictionary<CheckResultOrderingKey, SteeltoeHealthCheckResult>(CheckResultOrderingKeyComparer.Instance);

foreach ((string name, SteeltoeHealthCheckResult checkResult) in healthChecks)
{
if (healthCheck.Value.Status > result.Status)
if (checkResult.Status > result.Status)
{
result.Status = healthCheck.Value.Status;
result.Status = checkResult.Status;
}

result.Details.Add(healthCheck.Key, healthCheck.Value);
var orderingKey = new CheckResultOrderingKey(checkResult.Status, name);
orderedCheckResults.Add(orderingKey, checkResult);
}

foreach ((CheckResultOrderingKey orderingKey, SteeltoeHealthCheckResult checkResult) in orderedCheckResults)
{
result.Details.Add(orderingKey.Name, checkResult);
}

return result;
}

private sealed record CheckResultOrderingKey(SteeltoeHealthStatus Status, string Name);

private sealed class CheckResultOrderingKeyComparer : IComparer<CheckResultOrderingKey>
{
private static readonly List<SteeltoeHealthStatus> HealthStatusOrder =
[
SteeltoeHealthStatus.Down,
SteeltoeHealthStatus.OutOfService,
SteeltoeHealthStatus.Warning,
SteeltoeHealthStatus.Unknown,
SteeltoeHealthStatus.Up
];

public static CheckResultOrderingKeyComparer Instance { get; } = new();

private CheckResultOrderingKeyComparer()
{
}

public int Compare(CheckResultOrderingKey? x, CheckResultOrderingKey? y)
{
if (x == null || y == null)
{
return Comparer<CheckResultOrderingKey>.Default.Compare(x, y);
}

int result = HealthStatusOrder.IndexOf(x.Status).CompareTo(HealthStatusOrder.IndexOf(y.Status));

if (result == 0)
{
result = string.Compare(x.Name, y.Name, StringComparison.Ordinal);
}

return result;
}
}
}
3 changes: 2 additions & 1 deletion src/Common/test/Common.Test/ApplicationInstanceInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Steeltoe.Common.Extensions;
using Steeltoe.Common.TestResources;
using Steeltoe.Common.TestResources.IO;

namespace Steeltoe.Common.Test;
Expand Down Expand Up @@ -34,7 +35,7 @@ public async Task ReadsApplicationConfiguration()
""";

using var sandbox = new Sandbox();
string path = sandbox.CreateFile("appsettings.json", configJson);
string path = sandbox.CreateFile(MemoryFileProvider.DefaultAppSettingsFileName, configJson);
string directory = Path.GetDirectoryName(path)!;
string fileName = Path.GetFileName(path);
var builder = new ConfigurationBuilder();
Expand Down
61 changes: 61 additions & 0 deletions src/Common/test/TestResources/InactiveDiagnosticListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;

namespace Steeltoe.Common.TestResources;

/// <summary>
/// A no-op replacement for the built-in <see cref="DiagnosticListener" />.
/// </summary>
/// <para>
/// This type is registered by host builders used in tests. It prevents failure in DiagnosticObserverHttpExchangeRecorder when many tests are running.
/// </para>
internal sealed class InactiveDiagnosticListener()
: DiagnosticListener("Empty")
{
public override bool IsEnabled(string name)
{
return false;
}

public override bool IsEnabled(string name, object? arg1, object? arg2 = null)
{
return false;
}

public override IDisposable Subscribe(IObserver<KeyValuePair<string, object?>> observer)
{
return EmptyDisposable.Instance;
}

public override IDisposable Subscribe(IObserver<KeyValuePair<string, object?>> observer, Func<string, object?, object?, bool>? isEnabled)
{
return EmptyDisposable.Instance;
}

public override IDisposable Subscribe(IObserver<KeyValuePair<string, object?>> observer, Predicate<string>? isEnabled)
{
return EmptyDisposable.Instance;
}

// ReSharper disable once MethodOverloadWithOptionalParameter
public override IDisposable Subscribe(IObserver<KeyValuePair<string, object?>> observer, Func<string, object?, object?, bool>? isEnabled,
Action<Activity, object?>? onActivityImport = null, Action<Activity, object?>? onActivityExport = null)
{
return EmptyDisposable.Instance;
}

public override void Write(string name, object? value)
{
}

public override void OnActivityExport(Activity activity, object? payload)
{
}

public override void OnActivityImport(Activity activity, object? payload)
{
}
}
2 changes: 2 additions & 0 deletions src/Common/test/TestResources/MemoryFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace Steeltoe.Common.TestResources;

public sealed class MemoryFileProvider : IFileProvider
{
public const string DefaultAppSettingsFileName = "appsettings.json";

private static readonly char[] DirectorySeparators =
[
Path.DirectorySeparatorChar,
Expand Down
13 changes: 10 additions & 3 deletions src/Common/test/TestResources/TestHostApplicationBuilderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;

namespace Steeltoe.Common.TestResources;
Expand All @@ -21,7 +23,7 @@ public static class TestHostApplicationBuilderFactory
public static HostApplicationBuilder Create()
{
HostApplicationBuilder builder = Host.CreateEmptyApplicationBuilder(new HostApplicationBuilderSettings());
ConfigureBuilder(builder);
ConfigureBuilder(builder, true);

return builder;
}
Expand All @@ -39,13 +41,18 @@ public static HostApplicationBuilder Create(string[] args)
Args = args
});

ConfigureBuilder(builder);
ConfigureBuilder(builder, true);

return builder;
}

private static void ConfigureBuilder(HostApplicationBuilder builder)
private static void ConfigureBuilder(HostApplicationBuilder builder, bool deactivateDiagnostics)
{
builder.ConfigureContainer(new DefaultServiceProviderFactory(ValidatingServiceProviderOptions));

if (deactivateDiagnostics)
{
builder.Services.Replace(ServiceDescriptor.Singleton<DiagnosticListener, InactiveDiagnosticListener>());
}
}
}
13 changes: 10 additions & 3 deletions src/Common/test/TestResources/TestHostBuilderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;

namespace Steeltoe.Common.TestResources;
Expand All @@ -25,20 +27,20 @@ public static class TestHostBuilderFactory
public static HostBuilder Create()
{
var builder = new HostBuilder();
ConfigureBuilder(builder, false, false);
ConfigureBuilder(builder, false, false, true);

return builder;
}

public static HostBuilder CreateWeb()
{
var builder = new HostBuilder();
ConfigureBuilder(builder, true, true);
ConfigureBuilder(builder, true, true, true);

return builder;
}

private static void ConfigureBuilder(IHostBuilder builder, bool configureWebHost, bool useTestServer)
private static void ConfigureBuilder(HostBuilder builder, bool configureWebHost, bool useTestServer, bool deactivateDiagnostics)
{
builder.UseDefaultServiceProvider(ConfigureServiceProvider);

Expand All @@ -54,5 +56,10 @@ private static void ConfigureBuilder(IHostBuilder builder, bool configureWebHost
}
});
}

if (deactivateDiagnostics)
{
builder.ConfigureServices(services => services.Replace(ServiceDescriptor.Singleton<DiagnosticListener, InactiveDiagnosticListener>()));
}
}
}
13 changes: 10 additions & 3 deletions src/Common/test/TestResources/TestWebApplicationBuilderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Steeltoe.Common.TestResources;

Expand Down Expand Up @@ -52,7 +54,7 @@ public static WebApplicationBuilder Create(string[] args)
public static WebApplicationBuilder Create(WebApplicationOptions options)
{
WebApplicationBuilder builder = WebApplication.CreateEmptyBuilder(options);
ConfigureBuilder(builder, true);
ConfigureBuilder(builder, true, true);

return builder;
}
Expand Down Expand Up @@ -80,18 +82,23 @@ public static WebApplicationBuilder CreateDefault()
public static WebApplicationBuilder CreateDefault(bool useTestServer)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder();
ConfigureBuilder(builder, useTestServer);
ConfigureBuilder(builder, useTestServer, false);

return builder;
}

private static void ConfigureBuilder(WebApplicationBuilder builder, bool useTestServer)
private static void ConfigureBuilder(WebApplicationBuilder builder, bool useTestServer, bool deactivateDiagnostics)
{
builder.WebHost.UseDefaultServiceProvider(ConfigureServiceProvider);

if (useTestServer)
{
builder.WebHost.UseTestServer();
}

if (deactivateDiagnostics)
{
builder.Services.Replace(ServiceDescriptor.Singleton<DiagnosticListener, InactiveDiagnosticListener>());
}
}
}
11 changes: 9 additions & 2 deletions src/Common/test/TestResources/TestWebHostBuilderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Steeltoe.Common.TestResources;

Expand All @@ -29,12 +31,12 @@ public static WebHostBuilder Create()
public static WebHostBuilder Create(bool useTestServer)
{
var builder = new WebHostBuilder();
ConfigureBuilder(builder, useTestServer);
ConfigureBuilder(builder, useTestServer, true);

return builder;
}

private static void ConfigureBuilder(IWebHostBuilder builder, bool useTestServer)
private static void ConfigureBuilder(WebHostBuilder builder, bool useTestServer, bool deactivateDiagnostics)
{
builder.UseDefaultServiceProvider(ConfigureServiceProvider);
builder.Configure(EmptyAction);
Expand All @@ -43,5 +45,10 @@ private static void ConfigureBuilder(IWebHostBuilder builder, bool useTestServer
{
builder.UseTestServer();
}

if (deactivateDiagnostics)
{
builder.ConfigureServices(services => services.Replace(ServiceDescriptor.Singleton<DiagnosticListener, InactiveDiagnosticListener>()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ private static IEnumerable<IConfigurationProvider> FilterProviders(IEnumerable<I
{
foreach (IConfigurationProvider provider in providers)
{
if (predicate(provider))
{
yield return provider;
}

if (provider is ChainedConfigurationProvider chainedConfigurationProvider)
{
foreach (IConfigurationProvider match in EnumerateProviders(chainedConfigurationProvider.Configuration, predicate))
Expand All @@ -86,6 +81,11 @@ private static IEnumerable<IConfigurationProvider> FilterProviders(IEnumerable<I
yield return match;
}
}

if (predicate(provider))
{
yield return provider;
}
}
}
}
Loading
Loading