-
-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Allow logcat attachments to be previewed in Sentry (#3711)
- Loading branch information
1 parent
0b13b7a
commit 44d0c69
Showing
3 changed files
with
69 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Microsoft.Extensions.Options; | ||
#if ANDROID | ||
using Sentry.Android; | ||
#endif | ||
|
||
namespace Sentry.Maui.Tests; | ||
|
||
public class SentryMauiLogcatsTests | ||
{ | ||
private class Fixture | ||
{ | ||
public MauiAppBuilder Builder { get; } | ||
public FakeTransport Transport { get; private set; } = new FakeTransport(); | ||
public InMemoryDiagnosticLogger Logger { get; private set; } = new InMemoryDiagnosticLogger(); | ||
|
||
public Fixture() | ||
{ | ||
var builder = MauiApp.CreateBuilder(); | ||
builder.Services.AddSingleton(Substitute.For<IApplication>()); | ||
|
||
builder.Services.Configure<SentryMauiOptions>(options => | ||
{ | ||
options.Transport = Transport; | ||
options.Dsn = ValidDsn; | ||
options.AttachScreenshot = false; //Disable the screenshot attachment to have the logcat as primary attachment | ||
options.Debug = true; | ||
options.DiagnosticLogger = Logger; | ||
options.AutoSessionTracking = false; //Get rid of session envelope for easier Assert | ||
options.CacheDirectoryPath = null; //Do not wrap our FakeTransport with a caching transport | ||
options.FlushTimeout = TimeSpan.FromSeconds(10); | ||
}); | ||
Builder = builder; | ||
} | ||
} | ||
|
||
private readonly Fixture _fixture = new(); | ||
|
||
#if ANDROID | ||
[Fact] | ||
public void CaptureException_CheckLogcatType() | ||
{ | ||
var builder = _fixture.Builder.UseSentry(options => | ||
{ | ||
options.Android.LogCatIntegration = Android.LogCatIntegrationType.All; | ||
}); | ||
|
||
// Arrange | ||
var processor = Substitute.For<ISentryEventProcessorWithHint>(); | ||
using var app = builder.Build(); | ||
SentryHint hint = null; | ||
var options = app.Services.GetRequiredService<IOptions<SentryMauiOptions>>().Value; | ||
|
||
var scope = new Scope(options); | ||
|
||
// Act | ||
processor.Process(Arg.Any<SentryEvent>(), Arg.Do<SentryHint>(h => hint = h)).Returns(new SentryEvent()); | ||
options.AddEventProcessor(processor); | ||
|
||
_ = new SentryClient(options).CaptureEvent(new SentryEvent(), scope); | ||
|
||
|
||
// Assert | ||
hint.Should().NotBeNull(); | ||
hint.Attachments.First().ContentType.Should().Be("text/plain", hint.Attachments.First().ContentType); | ||
} | ||
#endif | ||
} |