-
Notifications
You must be signed in to change notification settings - Fork 887
Always log dashboard startup summary across auth modes #17206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
00682b5
Always log dashboard URL at startup regardless of auth mode
JamesNK 12bdff9
Always log dashboard URL regardless of launch profile settings
JamesNK 6e8e9c8
Update
JamesNK ebbb272
Log dashboard summary even when frontend endpoint is null
JamesNK a47caab
Clean up
JamesNK 53faa6c
Add Debug.Assert to validate single URL inputs in WriteDashboardSummary
JamesNK c0f3c73
Fix tests?
JamesNK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Aspire.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
| using Microsoft.Extensions.Logging.Testing; | ||
| using Xunit; | ||
|
|
||
| namespace Aspire.Dashboard.Tests; | ||
|
|
||
| public class LoggingHelpersTests | ||
| { | ||
| [Fact] | ||
| public void WriteDashboardUrl_WithToken_LogsLoginUrl() | ||
| { | ||
| var sink = new TestSink(); | ||
| var logger = new TestLogger("TestLogger", sink, enabled: true); | ||
|
|
||
| LoggingHelpers.WriteDashboardUrl(logger, "http://localhost:18888", "abc123", isContainer: false); | ||
|
|
||
| var write = Assert.Single(sink.Writes); | ||
| Assert.Equal(LogLevel.Information, write.LogLevel); | ||
| Assert.Contains("/login?t=abc123", write.Message); | ||
| Assert.Contains("Login to the dashboard at", write.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WriteDashboardUrl_WithToken_IsContainer_LogsContainerMessage() | ||
| { | ||
| var sink = new TestSink(); | ||
| var logger = new TestLogger("TestLogger", sink, enabled: true); | ||
|
|
||
| LoggingHelpers.WriteDashboardUrl(logger, "http://localhost:18888", "abc123", isContainer: true); | ||
|
|
||
| var write = Assert.Single(sink.Writes); | ||
| Assert.Equal(LogLevel.Information, write.LogLevel); | ||
| Assert.Contains("/login?t=abc123", write.Message); | ||
| Assert.Contains("URL may need changes depending on how network access to the container is configured", write.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WriteDashboardUrl_WithoutToken_LogsDashboardUrl() | ||
| { | ||
| var sink = new TestSink(); | ||
| var logger = new TestLogger("TestLogger", sink, enabled: true); | ||
|
|
||
| LoggingHelpers.WriteDashboardUrl(logger, "http://localhost:18888", token: null, isContainer: false); | ||
|
|
||
| var write = Assert.Single(sink.Writes); | ||
| Assert.Equal(LogLevel.Information, write.LogLevel); | ||
| Assert.Contains("The dashboard is available at", write.Message); | ||
| Assert.Contains("http://localhost:18888", write.Message); | ||
| Assert.DoesNotContain("/login?t=", write.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WriteDashboardUrl_WithoutToken_IsContainer_LogsContainerMessage() | ||
| { | ||
| var sink = new TestSink(); | ||
| var logger = new TestLogger("TestLogger", sink, enabled: true); | ||
|
|
||
| LoggingHelpers.WriteDashboardUrl(logger, "http://localhost:18888", token: null, isContainer: true); | ||
|
|
||
| var write = Assert.Single(sink.Writes); | ||
| Assert.Equal(LogLevel.Information, write.LogLevel); | ||
| Assert.Contains("The dashboard is available at", write.Message); | ||
| Assert.Contains("URL may need changes depending on how network access to the container is configured", write.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WriteDashboardUrl_EmptyToken_LogsDashboardUrlWithoutLogin() | ||
| { | ||
| var sink = new TestSink(); | ||
| var logger = new TestLogger("TestLogger", sink, enabled: true); | ||
|
|
||
| LoggingHelpers.WriteDashboardUrl(logger, "http://localhost:18888", token: "", isContainer: false); | ||
|
|
||
| var write = Assert.Single(sink.Writes); | ||
| Assert.Equal(LogLevel.Information, write.LogLevel); | ||
| Assert.Contains("The dashboard is available at", write.Message); | ||
| Assert.DoesNotContain("/login?t=", write.Message); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WriteDashboardUrl_InvalidUrl_DoesNotLog() | ||
| { | ||
| var sink = new TestSink(); | ||
| var logger = new TestLogger("TestLogger", sink, enabled: true); | ||
|
|
||
| LoggingHelpers.WriteDashboardUrl(logger, "not-a-url", token: "abc123", isContainer: false); | ||
|
|
||
| Assert.Empty(sink.Writes); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WriteDashboardUrl_NullUrl_DoesNotLog() | ||
| { | ||
| var sink = new TestSink(); | ||
| var logger = new TestLogger("TestLogger", sink, enabled: true); | ||
|
|
||
| LoggingHelpers.WriteDashboardUrl(logger, dashboardUrls: null, token: "abc123", isContainer: false); | ||
|
|
||
| Assert.Empty(sink.Writes); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WriteDashboardUrl_SemicolonDelimitedUrls_UsesFirstUrl() | ||
| { | ||
| var sink = new TestSink(); | ||
| var logger = new TestLogger("TestLogger", sink, enabled: true); | ||
|
|
||
| LoggingHelpers.WriteDashboardUrl(logger, "http://localhost:18888;http://localhost:19999", "mytoken", isContainer: false); | ||
|
|
||
| var write = Assert.Single(sink.Writes); | ||
| Assert.Contains("http://localhost:18888/login?t=mytoken", write.Message); | ||
| Assert.DoesNotContain("19999", write.Message); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.