-
Notifications
You must be signed in to change notification settings - Fork 804
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
Fix seq trailing slash, respect cancellation token, make SeqOptions.ApiKey nullable #1304
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9667b96
dont fetch the assembly name twice
MrSmoke ee61541
Use CancellationToken to SeqPublisher HttpClient
MrSmoke 80b94e4
Dispose the HttpClient for SeqPublisher
MrSmoke 174fc36
Build Uri in ctor
MrSmoke 444a2be
Add test for seq publisher trailing slash
MrSmoke f28fb8d
Use FluentAssertions extension methods
MrSmoke df33c0e
rename token to cancellationToken
MrSmoke fb9755f
run dotnet format
MrSmoke ce7e5cf
add null check for endpoint
MrSmoke 0aa3ce8
only add apiKey to seq publisher if supplied
MrSmoke 4c1d001
add test for when seq endpoint is null
MrSmoke f5574f4
update seq publisher approved test
MrSmoke a0a3462
Update src/HealthChecks.Publisher.Seq/SeqPublisher.cs
MrSmoke 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 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 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 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 |
---|---|---|
|
@@ -9,12 +9,11 @@ public void add_healthcheck_when_properly_configured() | |
services | ||
.AddHealthChecks() | ||
.AddSeqPublisher(setup => | ||
new SeqOptions() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 funny test fix |
||
{ | ||
ApiKey = "apiKey", | ||
DefaultInputLevel = Seq.SeqInputLevel.Information, | ||
Endpoint = "endpoint" | ||
}); | ||
{ | ||
setup.Endpoint = "endpoint"; | ||
setup.DefaultInputLevel = Seq.SeqInputLevel.Information; | ||
setup.ApiKey = "apiKey"; | ||
}); | ||
|
||
using var serviceProvider = services.BuildServiceProvider(); | ||
var publisher = serviceProvider.GetService<IHealthCheckPublisher>(); | ||
|
63 changes: 63 additions & 0 deletions
63
test/HealthChecks.Publisher.Seq.Tests/Functional/SeqPublisherTests.cs
This file contains 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,63 @@ | ||
using System.Net; | ||
|
||
namespace HealthChecks.Publisher.Seq.Tests.Functional; | ||
|
||
public class seq_publisher_should | ||
{ | ||
[Fact] | ||
public async Task handle_trailing_slash_in_endpoint() | ||
{ | ||
var options = new SeqOptions | ||
{ | ||
ApiKey = "test-key", | ||
Endpoint = "http://localhost:5341/" | ||
}; | ||
|
||
var expectedUri = new Uri("http://localhost:5341/api/events/raw?apiKey=test-key"); | ||
|
||
// Setup mocks | ||
using var handler = new MockClientHandler(); | ||
HttpClient HttpClientFactory() => new(handler); | ||
|
||
var testReport = new HealthReport(new Dictionary<string, HealthReportEntry>(), TimeSpan.Zero); | ||
|
||
// Create publisher and publish | ||
var publisher = new SeqPublisher(HttpClientFactory, options); | ||
await publisher.PublishAsync(testReport, CancellationToken.None); | ||
|
||
handler.Request.ShouldNotBeNull(); | ||
handler.Request.RequestUri.ShouldBe(expectedUri); | ||
} | ||
|
||
[Fact] | ||
public void throw_exception_when_endpoint_is_null() | ||
{ | ||
var options = new SeqOptions | ||
{ | ||
ApiKey = "test-key", | ||
Endpoint = null! | ||
}; | ||
|
||
HttpClient HttpClientFactory() => new(); | ||
|
||
var ex = Should.Throw<ArgumentNullException>(() => new SeqPublisher(HttpClientFactory, options)); | ||
ex.ParamName.ShouldBe(nameof(SeqOptions.Endpoint)); | ||
} | ||
|
||
private class MockClientHandler : HttpClientHandler | ||
{ | ||
public HttpRequestMessage? Request; | ||
|
||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
Request = request; | ||
|
||
var response = new HttpResponseMessage | ||
{ | ||
StatusCode = HttpStatusCode.OK | ||
}; | ||
|
||
return Task.FromResult(response); | ||
} | ||
} | ||
} |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a look at the official API client for seq and it seems that the
ApiKey
can be null so it probably makes sense for it to be null here too?https://github.com/datalust/seq-api/blob/dev/src/Seq.Api/Client/SeqApiClient.cs#L75=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes