public void Environment_BothOnOptionsAndEnvVar_ValueFromOption() { const string expected = "environment"; const string other = "other"; Configure = o => o.Environment = expected; EnvironmentVariableGuard.WithVariable("ASPNETCORE_ENVIRONMENT", other, () => { Build(); _ = HttpClient.GetAsync("/throw").GetAwaiter().GetResult(); _ = Worker.Received(1).EnqueueEnvelope(Arg.Is <Envelope>(e => e.Items .Select(i => i.Payload) .OfType <JsonSerializable>() .Select(i => i.Source) .OfType <SentryEvent>() .Single() .Environment == expected )); }); }
public void Locate_WithoutEnvironmentVariable_ReturnsNull() { EnvironmentVariableGuard.WithVariable( Sentry.Internal.Constants.ReleaseEnvironmentVariable, null, () => { Assert.Null(EnvironmentLocator.LocateFromEnvironmentVariable()); }); }
public void GetCurrent_WithoutEnvironmentVariable_ReturnsNull() { EnvironmentVariableGuard.WithVariable( Constants.ReleaseEnvironmentVariable, null, () => { Assert.Null(EnvironmentLocator.GetCurrent()); }); }
public void GetCurrent_WithoutEnvironmentVariable_VersionOfEntryAssembly() { EnvironmentVariableGuard.WithVariable( Constants.ReleaseEnvironmentVariable, null, () => { Assert.Equal(Assembly.GetEntryAssembly()?.GetNameAndVersion().Version, ReleaseLocator.GetCurrent()); }); }
public void FindDsnOrDisable_NoEnvironmentVariableNorAttribute_ReturnsDisabledDsn() { EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, null, () => { Assert.Equal(DisableSdkDsnValue, DsnLocator.FindDsnStringOrDisable()); }); }
public void Init_DisableDsnEnvironmentVariable_DisablesSdk() { EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, DisableSdkDsnValue, () => { using (SentrySdk.Init()) Assert.False(SentrySdk.IsEnabled); }); }
public void Init_CallbackWithoutDsn_ValidDsnEnvironmentVariable_LocatesDsnEnvironmentVariable() { EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, ValidDsnWithSecret, () => { using (SentrySdk.Init(c => { })) Assert.True(SentrySdk.IsEnabled); }); }
public void Init_CallbackWithoutDsn_InvalidDsnEnvironmentVariable_DisabledSdk() { EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, InvalidDsn, () => { using (SentrySdk.Init(c => { })) Assert.False(SentrySdk.IsEnabled); }); }
public void Init_DisableDsnEnvironmentVariable_DisablesSdk() { EnvironmentVariableGuard.WithVariable( Sentry.Internals.Constants.DsnEnvironmentVariable, Sentry.Internals.Constants.DisableSdkDsnValue, () => { SentryCore.Init(); Assert.False(SentryCore.IsEnabled); }); }
public void Init_ValidDsnEnvironmentVariable_EnablesSdk() { EnvironmentVariableGuard.WithVariable( Sentry.Internals.Constants.DsnEnvironmentVariable, DsnSamples.ValidDsnWithSecret, () => { SentryCore.Init(); Assert.True(SentryCore.IsEnabled); }); }
public void Init_ValidDsnEnvironmentVariable_EnablesSdk() { EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, ValidDsnWithSecret, () => { using (SentrySdk.Init()) Assert.True(SentrySdk.IsEnabled); }); }
public void Locate_WithEnvironmentVariable_ReturnsEnvironmentVariableValue() { const string expectedVersion = "the environment name"; EnvironmentVariableGuard.WithVariable( Sentry.Internal.Constants.EnvironmentEnvironmentVariable, expectedVersion, () => { Assert.Equal(expectedVersion, EnvironmentLocator.LocateFromEnvironmentVariable()); }); }
public void Current_CachesValue() { var expected = EnvironmentLocator.Current; EnvironmentVariableGuard.WithVariable( Sentry.Internal.Constants.ReleaseEnvironmentVariable, Guid.NewGuid().ToString(), () => { Assert.Equal(expected, EnvironmentLocator.Current); }); }
public void GetCurrent_WithEnvironmentVariable_VersionOfEnvironmentVariable() { const string expectedVersion = "the version"; EnvironmentVariableGuard.WithVariable( Constants.ReleaseEnvironmentVariable, expectedVersion, () => { Assert.Equal(expectedVersion, ReleaseLocator.GetCurrent()); }); }
public void ResolveFromEnvironment_WithEnvironmentVariable_VersionOfEnvironmentVariable() { const string expectedVersion = "the version"; EnvironmentVariableGuard.WithVariable( Sentry.Internal.Constants.ReleaseEnvironmentVariable, expectedVersion, () => { Assert.Equal(expectedVersion, ReleaseLocator.LocateFromEnvironment()); }); }
public void GetCurrent_WithEnvironmentVariable_ReturnsEnvironmentVariableValue() { const string expectedVersion = "the environment name"; EnvironmentVariableGuard.WithVariable( Constants.EnvironmentEnvironmentVariable, expectedVersion, () => { Assert.Equal(expectedVersion, EnvironmentLocator.GetCurrent()); }); }
[InlineData("Production")] // Custom setting which is the same as ASPNET_ENVIRONMENT. But because this is manually set, don't change it. public void Filters_Environment_SentryEnvironment_Set(string environment) { // Arrange. EnvironmentVariableGuard.WithVariable(Internal.Constants.EnvironmentEnvironmentVariable, environment, () => { // Act. _sut.Configure(_target); // Assert. Assert.Equal(environment, _target.Environment); }); }
public void Init_InvalidDsnEnvironmentVariable_Throws() { EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, // If the variable was set, to non empty string but value is broken, better crash than silently disable InvalidDsn, () => { var ex = Assert.Throws <ArgumentException>(() => SentrySdk.Init()); Assert.Equal("Invalid DSN: A Project Id is required.", ex.Message); }); }
public void FindDsnOrDisable_DsnOnEnvironmentVariable_ReturnsTheDsn() { const string expected = DsnSamples.ValidDsnWithoutSecret; EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, expected, () => { Assert.Equal(expected, DsnLocator.FindDsnStringOrDisable()); }); }
public void FindDsnOrDisable_DsnOnEnvironmentVariableAndAttribute_ReturnsTheDsnFromEnvironmentVariable() { const string expected = DsnSamples.ValidDsnWithoutSecret; EnvironmentVariableGuard.WithVariable( DsnEnvironmentVariable, expected, () => { var asm = AssemblyCreationHelper.CreateAssemblyWithDsnAttribute(DsnSamples.ValidDsnWithSecret); Assert.Equal(expected, DsnLocator.FindDsnStringOrDisable(asm)); }); }
public void Environment_NotOnOptions_ValueFromEnvVar() { const string expected = "environment"; EnvironmentVariableGuard.WithVariable("ASPNETCORE_ENVIRONMENT", expected, () => { Build(); HttpClient.GetAsync("/throw").GetAwaiter().GetResult(); Worker.Received(1).EnqueueEvent(Arg.Is <SentryEvent>(e => e.Environment == expected)); }); }
[InlineData("aBcDe F !@#$ gHi", "aBcDe F !@#$ gHi")] // Provided: nothing will change. (Case check) public void Process_NoEnvironmentOnOptions_SameAsEnvironmentVariable(string environment, string expectedEnvironment) { var sut = _fixture.GetSut(); var evt = new SentryEvent(); EnvironmentVariableGuard.WithVariable( Constants.EnvironmentEnvironmentVariable, environment, () => { _ = sut.Process(evt); }); Assert.Equal(expectedEnvironment, evt.Environment); }
public void Process_NoEnvironmentOnOptions_SameAsEnvironmentVariable() { const string expected = "Staging"; var evt = new SentryEvent(); EnvironmentVariableGuard.WithVariable( Constants.EnvironmentEnvironmentVariable, expected, () => { Sut.Process(evt); }); Assert.Equal(expected, evt.Environment); }
public void ConfigureLogging_ModifiesReleaseLocatorAndReadsKRevisionEnvVar_AppendsToRelease() { var sut = new SentryStartup(); EnvironmentVariableGuard.WithVariable("K_REVISION", "9", () => { sut.ConfigureLogging(WebHostBuilderContext, LoggingBuilder); var provider = LoggingBuilder.Services.BuildServiceProvider(); var option = provider.GetRequiredService <IOptions <SentryAspNetCoreOptions> >(); Assert.Null(option.Value.Release); Assert.EndsWith("+9", ReleaseLocator.Resolve(option.Value)); }); }
public void ResolveFromEnvironment_WithoutEnvironmentVariable_VersionOfEntryAssembly() { var ass = Assembly.GetEntryAssembly(); #if NET461 Skip.If(ass == null, "GetEntryAssembly can return null on net461. eg on Mono or in certain test runners."); #endif EnvironmentVariableGuard.WithVariable( Sentry.Internal.Constants.ReleaseEnvironmentVariable, null, () => { Assert.Equal( $"{ass!.GetName().Name}@{ass!.GetNameAndVersion().Version}", ReleaseLocator.LocateFromEnvironment()); });
public void ResolveFromEnvironment_WithoutEnvironmentVariable_VersionOfEntryAssembly() { #if NET461 Skip.If(Runtime.Current.IsMono(), "GetEntryAssembly returning null on Mono."); #endif var ass = Assembly.GetEntryAssembly(); EnvironmentVariableGuard.WithVariable( Sentry.Internal.Constants.ReleaseEnvironmentVariable, null, () => { Assert.Equal( $"{ass!.GetName().Name}@{ass!.GetNameAndVersion().Version}", ReleaseLocator.LocateFromEnvironment() ); });
public void Environment_BothOnOptionsAndEnvVar_ValueFromOption() { const string expected = "environment"; const string other = "other"; Configure = o => o.Environment = expected; EnvironmentVariableGuard.WithVariable("ASPNETCORE_ENVIRONMENT", other, () => { Build(); HttpClient.GetAsync("/throw").GetAwaiter().GetResult(); Worker.Received(1).EnqueueEvent(Arg.Is <SentryEvent>(e => e.Environment == expected)); }); }
public void Environment_NotOnOptions_ValueFromEnvVar() { const string expected = "environment"; EnvironmentVariableGuard.WithVariable("ASPNETCORE_ENVIRONMENT", expected, () => { Build(); _ = HttpClient.GetAsync("/throw").GetAwaiter().GetResult(); _ = Worker.Received(1).EnqueueEnvelope(Arg.Is <Envelope>(e => e.Items .Select(i => i.Payload) .OfType <SentryEvent>() .Single() .Environment == expected )); }); }