Skip to content

Commit

Permalink
Add additional tests for CI Visibility test behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Jan 6, 2025
1 parent 9194a87 commit 2635b99
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Datadog.Trace.Tests.Configuration
{
public class CIVisibilitySettingsTests : SettingsTestsBase
{
private static readonly string ExpectedExcludedSession = "/session/FakeSessionIdForPollingPurposes".ToUpperInvariant();

[Theory]
[MemberData(nameof(BooleanTestCases), null)]
public void Enabled(string value, bool? expected)
Expand Down Expand Up @@ -185,5 +187,106 @@ public void ForceAgentsEvpProxy(string value, string expected)

settings.ForceAgentsEvpProxy.Should().Be(expected);
}

[Theory]
[InlineData("some-service", "true")]
[InlineData(null, "false")]
public void AddsUserProvidedTestServiceTagToGlobalTags(string serviceName, string expectedTag)
{
var source = CreateConfigurationSource((ConfigurationKeys.ServiceName, serviceName));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.GlobalTags.Should()
.ContainKey(Datadog.Trace.Ci.Tags.CommonTags.UserProvidedTestServiceTag)
.WhoseValue.Should()
.Be(expectedTag);
}

[Fact]
public void ServiceNameIsNormalized()
{
var originalName = "My Service Name!";
var normalizedName = "my_service_name";

var source = CreateConfigurationSource((ConfigurationKeys.ServiceName, originalName));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.ServiceName.Should().Be(normalizedName);
}

[Fact]
public void AddsFakeSessionToExcludedHttpClientUrls()
{
var source = CreateConfigurationSource();

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.HttpClientExcludedUrlSubstrings
.Should()
.Contain(ExpectedExcludedSession);
}

[Fact]
public void AddsFakeSessionToExcludedHttpClientUrls_WhenUrlsAlreadyExist()
{
var source = CreateConfigurationSource(
(ConfigurationKeys.HttpClientExcludedUrlSubstrings, "/some-url/path"));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.HttpClientExcludedUrlSubstrings
.Should()
.Contain(ExpectedExcludedSession);
}

[Fact]
public void AddsFakeSessionToExcludedHttpClientUrls_WhenRunningInAas()
{
var source = CreateConfigurationSource(
(ConfigurationKeys.AzureAppService.AzureAppServicesContextKey, "true"),
(ConfigurationKeys.HttpClientExcludedUrlSubstrings, "/some-url/path"));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.HttpClientExcludedUrlSubstrings
.Should()
.Contain(ExpectedExcludedSession);
}

[Fact]
public void WhenLogsEnabled_AddsDirectSubmission()
{
var source = CreateConfigurationSource(
(ConfigurationKeys.CIVisibility.Logs, "true"));

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.LogSubmissionSettings
.EnabledIntegrationNames
.Should()
.Contain(nameof(IntegrationId.XUnit));
}

[Fact]
public void WhenLogsNotEnabled_DoesNotAddDirectSubmission()
{
var source = CreateConfigurationSource();

var ciVisSettings = new CIVisibilitySettings(source, NullConfigurationTelemetry.Instance);
var tracerSettings = ciVisSettings.InitializeTracerSettings([source]);

tracerSettings.LogSubmissionSettings
.EnabledIntegrationNames
.Should()
.NotContain(nameof(IntegrationId.XUnit));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ public void Environment(string value, string expected)

[Theory]
[InlineData("test", null, null, "test")]
[InlineData("My Service Name!", null, null, "My Service Name!")]
[InlineData("test", null, "ignored_otel", "test")]
[InlineData("test", "error", "ignored_otel", "test")]
[InlineData(null, "test", null, "test")]
Expand Down

0 comments on commit 2635b99

Please sign in to comment.