-
-
Notifications
You must be signed in to change notification settings - Fork 230
feat: Added internal bool CaptureAttachment to Hub
#4357
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 all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ac1b058
internal capture attachment
bitsandfoxes 3f38f43
added tests
bitsandfoxes 38e4bc6
move to hub and made internal
bitsandfoxes 57dadaa
fixed hubtests
bitsandfoxes cbe5e5c
fix build target order
bitsandfoxes 1df61f8
keep envelope creation from attachment as internal
bitsandfoxes 7b8a454
reverted messed up targets change
bitsandfoxes 94f52dc
upsi
bitsandfoxes edec8ee
comment
bitsandfoxes 117f61f
moved the attachment null check into the hub
bitsandfoxes 5f575de
Merge remote-tracking branch 'origin/main' into feat/capture-attachment
bitsandfoxes 888a04b
added nullattachmentcontent
bitsandfoxes 3054ba1
use byteattachmentcontent
bitsandfoxes 7595486
tweaks to envelope creation
bitsandfoxes d251af6
use instance instead
bitsandfoxes 80585ef
tests
bitsandfoxes 9ca0af6
comment
bitsandfoxes b0f890a
made nullattachment ctor private
bitsandfoxes 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,10 @@ | ||
| namespace Sentry.Testing; | ||
|
|
||
| internal sealed class NullAttachmentContent : IAttachmentContent | ||
|
bitsandfoxes marked this conversation as resolved.
|
||
| { | ||
| public static NullAttachmentContent Instance { get; } = new(); | ||
|
|
||
| public Stream GetStream() => Stream.Null; | ||
|
|
||
| private NullAttachmentContent() { } | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -1730,6 +1730,67 @@ public void CaptureFeedback_ConfigureScope_ScopeApplied(bool enabled) | |
| _fixture.Client.Received(enabled ? 1 : 0).CaptureFeedback(Arg.Any<SentryFeedback>(), Arg.Is<Scope>(s => s.Tags["foo"] == "bar"), Arg.Any<SentryHint>()); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(true)] | ||
| [InlineData(false)] | ||
| public void CaptureAttachment_HubEnabled(bool enabled) | ||
| { | ||
| // Arrange | ||
| var hub = _fixture.GetSut(); | ||
| if (!enabled) | ||
| { | ||
| hub.Dispose(); | ||
| } | ||
|
|
||
| _fixture.Client.CaptureEnvelope(Arg.Any<Envelope>()).Returns(true); | ||
|
bitsandfoxes marked this conversation as resolved.
|
||
|
|
||
| var eventId = SentryId.Create(); | ||
| var attachment = new SentryAttachment( | ||
| AttachmentType.Default, | ||
| new ByteAttachmentContent("test content"u8.ToArray()), | ||
|
Member
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. question: could/should we add an internal ByteAttachmentContent(ReadOnlySpan<byte> bytes) => _bytes = bytes.ToArray();Or is that overkill, because we only have 2 usages that would be shortened. |
||
| "test.txt", | ||
| "text/plain"); | ||
|
|
||
| // Act | ||
| var result = hub.CaptureAttachment(eventId, attachment); | ||
|
|
||
| // Assert | ||
| result.Should().Be(enabled); | ||
| _fixture.Client.Received(enabled ? 1 : 0).CaptureEnvelope(Arg.Any<Envelope>()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CaptureAttachment_SentryIdEmpty_ReturnsFalse() | ||
| { | ||
| // Arrange | ||
| var hub = _fixture.GetSut(); | ||
|
|
||
| var eventId = SentryId.Empty; | ||
| var attachment = new SentryAttachment(AttachmentType.Default, NullAttachmentContent.Instance, "test.txt", "text/plain"); | ||
|
|
||
| // Act | ||
| var result = hub.CaptureAttachment(eventId, attachment); | ||
|
|
||
| // Assert | ||
| result.Should().Be(false); | ||
| _fixture.Client.DidNotReceive().CaptureEnvelope(Arg.Any<Envelope>()); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void CaptureAttachment_AttachmentNull_ReturnsFalse() | ||
| { | ||
| // Arrange | ||
| var hub = _fixture.GetSut(); | ||
| var eventId = SentryId.Create(); | ||
|
|
||
| // Act | ||
| var result = hub.CaptureAttachment(eventId, null!); | ||
|
|
||
| // Assert | ||
| result.Should().Be(false); | ||
| _fixture.Client.DidNotReceive().CaptureEnvelope(Arg.Any<Envelope>()); | ||
| } | ||
|
|
||
| [Theory] | ||
| [InlineData(true)] | ||
| [InlineData(false)] | ||
|
|
||
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
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.