From 0d5aa507da733561a3060a14871b78d18ed4d351 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Mon, 25 Mar 2024 08:18:54 +0800 Subject: [PATCH] PR feedback --- .../DashboardWebApplication.cs | 3 ++- .../Integration/StartupTests.cs | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Aspire.Dashboard/DashboardWebApplication.cs b/src/Aspire.Dashboard/DashboardWebApplication.cs index 4bd4da38d0..bf2e23e11f 100644 --- a/src/Aspire.Dashboard/DashboardWebApplication.cs +++ b/src/Aspire.Dashboard/DashboardWebApplication.cs @@ -67,9 +67,10 @@ public DashboardWebApplication(Action? configureBuilder = builder.Logging.AddFilter("Microsoft.AspNetCore.Server.Kestrel", LogLevel.Error); #endif + // Allow for a user specified JSON config file on disk. Throw an error if the specified file doesn't exist. if (builder.Configuration[DashboardConfigNames.DashboardConfigFilePathName.ConfigKey] is { Length: > 0 } configFilePath) { - builder.Configuration.AddJsonFile(configFilePath, optional: true, reloadOnChange: true); + builder.Configuration.AddJsonFile(configFilePath, optional: false, reloadOnChange: true); } var dashboardConfigSection = builder.Configuration.GetSection("Dashboard"); diff --git a/tests/Aspire.Dashboard.Tests/Integration/StartupTests.cs b/tests/Aspire.Dashboard.Tests/Integration/StartupTests.cs index 7da83f8817..dbdbac51cc 100644 --- a/tests/Aspire.Dashboard.Tests/Integration/StartupTests.cs +++ b/tests/Aspire.Dashboard.Tests/Integration/StartupTests.cs @@ -57,6 +57,24 @@ public async Task Configuration_NoExtraConfig_Error() s => s.Contains("Dashboard:Otlp:AuthMode")); } + [Fact] + public async Task Configuration_ConfigFilePathDoesntExist_Error() + { + // Arrange & Act + var configFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); + var ex = await Assert.ThrowsAsync(async () => + { + await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(_testOutputHelper, + additionalConfiguration: data => + { + data[DashboardConfigNames.DashboardConfigFilePathName.ConfigKey] = configFilePath; + }); + }); + + // Assert + Assert.Contains(configFilePath, ex.Message); + } + [Fact] public async Task Configuration_OptionsMonitor_CanReadConfiguration() {