Skip to content
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

Drop FluentAssertions #587

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="xunit" Version="2.8.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#if NET

using System.IO.Compression;
using FluentAssertions;
using FluentAssertions.Execution;
using Google.Protobuf.Collections;
using OpenTelemetry.Proto.Collector.Logs.V1;
using OpenTelemetry.Proto.Common.V1;
Expand Down Expand Up @@ -49,7 +47,7 @@ public async Task SubmitAllocationSamples()
RunTestApplication();
var logsData = logsCollector.GetAllLogs();

logsData.Length.Should().BeGreaterOrEqualTo(expected: 1);
Assert.True(logsData.Length > 0);

await DumpLogRecords(logsData);

Expand All @@ -68,14 +66,11 @@ public async Task SubmitAllocationSamples()
profiles.Add(profile);
}

using (new AssertionScope())
{
AllShouldHaveBasicAttributes(logRecords, ConstantValuedAttributes("allocation"));
ProfilesContainAllocationValue(profiles);
RecordsContainFrameCountAttribute(logRecords);
ResourceContainsExpectedAttributes(dataResourceLog.Resource);
HasNameAndVersionSet(instrumentationLibraryLogs.Scope);
}
AllShouldHaveBasicAttributes(logRecords, ConstantValuedAttributes("allocation"));
ProfilesContainAllocationValue(profiles);
RecordsContainFrameCountAttribute(logRecords);
ResourceContainsExpectedAttributes(dataResourceLog.Resource);
HasNameAndVersionSet(instrumentationLibraryLogs.Scope);

logRecords.Clear();
}
Expand All @@ -94,7 +89,7 @@ public async Task SubmitThreadSamples()
var logsData = logsCollector.GetAllLogs();
// The application works for 6 seconds with debug logging enabled we expect at least 2 attempts of thread sampling in CI.
// On a dev box it is typical to get at least 4 but the CI machines seem slower, using 2
logsData.Length.Should().BeGreaterOrEqualTo(expected: 2);
Assert.True(logsData.Length > 2);

await DumpLogRecords(logsData);

Expand All @@ -118,14 +113,11 @@ public async Task SubmitThreadSamples()

containStackTraceForClassHierarchy |= profiles.Any(profile => ContainsStackTrace(profile, expectedStackTrace));

using (new AssertionScope())
{
AllShouldHaveBasicAttributes(logRecords, ConstantValuedAttributes("cpu"));
ProfilesDoNotContainAnyValue(profiles);
RecordsContainFrameCountAttribute(logRecords);
ResourceContainsExpectedAttributes(dataResourceLog.Resource);
HasNameAndVersionSet(instrumentationLibraryLogs.Scope);
}
AllShouldHaveBasicAttributes(logRecords, ConstantValuedAttributes("cpu"));
ProfilesDoNotContainAnyValue(profiles);
RecordsContainFrameCountAttribute(logRecords);
ResourceContainsExpectedAttributes(dataResourceLog.Resource);
HasNameAndVersionSet(instrumentationLibraryLogs.Scope);

logRecords.Clear();
}
Expand All @@ -137,23 +129,23 @@ private static void ProfilesContainAllocationValue(List<Profile> profiles)
{
foreach (var profile in profiles)
{
profile.Samples.All(x => x.Values.Length == 1).Should().BeTrue();
Assert.All(profile.Samples, x => Assert.Single(x.Values));
}
}

private static void ProfilesDoNotContainAnyValue(List<Profile> profiles)
{
foreach (var profile in profiles)
{
profile.Samples.All(x => x.Values.Length == 0).Should().BeTrue();
Assert.All(profile.Samples, x => Assert.Empty(x.Values));
}
}

private static void RecordsContainFrameCountAttribute(RepeatedField<LogRecord> logRecords)
{
foreach (var logRecord in logRecords)
{
logRecord.Attributes.Should().Contain(attr => attr.Key == "profiling.data.total.frame.count");
Assert.Single(logRecord.Attributes, attr => attr.Key == "profiling.data.total.frame.count");
}
}

Expand Down Expand Up @@ -185,7 +177,7 @@ private static void AllShouldHaveBasicAttributes(RepeatedField<LogRecord> logRec
{
foreach (var attribute in attributes)
{
logRecord.Attributes.Should().ContainEquivalentOf(attribute);
Assert.Contains(attribute, logRecord.Attributes);
}
}
}
Expand All @@ -208,8 +200,8 @@ private static void ResourceContainsExpectedAttributes(global::OpenTelemetry.Pro

private static void HasNameAndVersionSet(InstrumentationScope instrumentationScope)
{
instrumentationScope.Name.Should().Be("otel.profiling");
instrumentationScope.Version.Should().Be("0.1.0");
Assert.Equal("otel.profiling", instrumentationScope.Name);
Assert.Equal("0.1.0", instrumentationScope.Version);
}

private static bool ContainsStackTrace(Profile profile, string expectedStackTrace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using System.Reflection;
using FluentAssertions;
using OpenTelemetry.Proto.Common.V1;
using OpenTelemetry.Proto.Resource.V1;

Expand Down Expand Up @@ -52,11 +51,11 @@ internal static void AssertProfileResources(Resource resource)

foreach (var constantAttribute in constantAttributes)
{
resource.Attributes.Should().ContainEquivalentOf(constantAttribute);
Assert.Contains(constantAttribute, resource.Attributes);
}

// asserting resource attribute without values
resource.Attributes.Should().Contain(value => value.Key == "host.name");
resource.Attributes.Should().Contain(value => value.Key == "process.pid");
Assert.Single(resource.Attributes, value => value.Key == "host.name");
Assert.Single(resource.Attributes, value => value.Key == "process.pid");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

using System.Diagnostics;
using System.Reflection;
using FluentAssertions;
using Xunit.Abstractions;

namespace Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests.Helpers;
Expand Down Expand Up @@ -147,8 +146,8 @@ public void RunTestApplication(TestSettings testSettings = null)
Output.WriteLine("Exit Code: " + process.ExitCode);
Output.WriteResult(helper);

processTimeout.Should().BeFalse("Test application timed out");
process.ExitCode.Should().Be(0, "Test application exited with non-zero exit code");
Assert.False(processTimeout, "Test application timed out");
Assert.Equal(0, process.ExitCode);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
// limitations under the License.
// </copyright>

using FluentAssertions;
using Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests.Helpers;
using Xunit.Abstractions;

Expand All @@ -50,7 +49,7 @@ public SelfContainedTests(ITestOutputHelper output)
// The self-contained app is going to have an extra folder before it: the one
// with a RID like "win-x64", "linux-x64", etc.
var childrenDirs = Directory.GetDirectories(nonSelfContainedOutputDir);
childrenDirs.Should().ContainSingle();
Assert.Single(childrenDirs);

_selfContainedAppDir = childrenDirs[0];
}
Expand Down Expand Up @@ -92,7 +91,7 @@ private void RunInstrumentationTarget(string instrumentationTarget)
using var process = InstrumentedProcessHelper.Start(instrumentationScriptPath, instrumentationTarget, EnvironmentHelper);
using var helper = new ProcessHelper(process);

process.Should().NotBeNull();
Assert.NotNull(process);

bool processTimeout = !process!.WaitForExit((int)Helpers.Timeout.ProcessExit.TotalMilliseconds);
if (processTimeout)
Expand All @@ -104,8 +103,8 @@ private void RunInstrumentationTarget(string instrumentationTarget)
Output.WriteLine("Exit Code: " + process.ExitCode);
Output.WriteResult(helper);

processTimeout.Should().BeFalse("test application should NOT have timed out");
process.ExitCode.Should().Be(0, "test application should NOT have non-zero exit code");
Assert.False(processTimeout, "test application should NOT have timed out");
Assert.Equal(0, process.ExitCode);
}

private void RunAndAssertHttpSpans(Action appLauncherAction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#if NET

using FluentAssertions;
using FluentAssertions.Execution;
using Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests.Helpers;
using Xunit.Abstractions;

Expand Down Expand Up @@ -50,7 +48,8 @@ public async Task SubmitRequest(bool isEnabled, bool captureHeaders)
{
if (captureHeaders)
{
return span.Attributes.FirstOrDefault(x => x.Key == "http.request.header.custom-request-test-header")?.Value.StringValue == "Test-Value";
return span.Attributes.FirstOrDefault(x => x.Key == "http.request.header.custom-request-test-header")
?.Value.StringValue == "Test-Value";
}

return true;
Expand Down Expand Up @@ -79,18 +78,15 @@ public async Task SubmitRequest(bool isEnabled, bool captureHeaders)

Output.WriteResult(helper);

using (new AssertionScope())
if (isEnabled)
{
if (isEnabled)
{
response.Headers.Should().Contain(x => x.Key == "Server-Timing");
response.Headers.Should().Contain(x => x.Key == "Access-Control-Expose-Headers");
}
else
{
response.Headers.Should().NotContain(x => x.Key == "Server-Timing");
response.Headers.Should().NotContain(x => x.Key == "Access-Control-Expose-Headers");
}
Assert.Single(response.Headers, x => x.Key == "Server-Timing");
Assert.Single(response.Headers, x => x.Key == "Access-Control-Expose-Headers");
}
else
{
Assert.DoesNotContain(response.Headers, x => x.Key == "Server-Timing");
Assert.DoesNotContain(response.Headers, x => x.Key == "Access-Control-Expose-Headers");
}

collector.AssertExpectations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
// limitations under the License.
// </copyright>

using FluentAssertions;
using Splunk.OpenTelemetry.AutoInstrumentation.IntegrationTests.Helpers;
using Xunit.Abstractions;

Expand Down Expand Up @@ -181,7 +180,7 @@ public void ManagedLogsHaveNoSensitiveData()

var managedLog = tempLogsDirectory.GetFiles("otel-dotnet-auto-*-Splunk-*.log").Single();
var managedLogContent = File.ReadAllText(managedLog.FullName);
managedLogContent.Should().NotBeNullOrWhiteSpace();
Assert.False(string.IsNullOrWhiteSpace(managedLogContent));

var environmentVariables = ParseSettingsLog(managedLogContent, "Environment Variables:");
VerifyVariables(environmentVariables);
Expand All @@ -198,14 +197,14 @@ public void ManagedLogsHaveNoSensitiveData()

void VerifyVariables(ICollection<KeyValuePair<string, string>> options)
{
options.Should().NotBeEmpty();
Assert.NotEmpty(options);

var secretVariables = options
.Where(item => secretIdentificators.Any(i => item.Key.Contains(i)))
.ToList();

secretVariables.Should().NotBeEmpty();
secretVariables.Should().AllSatisfy(secret => secret.Value.Should().Be("<hidden>"));
Assert.NotEmpty(secretVariables);
Assert.All(secretVariables, secret => Assert.Equal("<hidden>", secret.Value));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- Suppress warnings about lowercase variable names in generated code -->
Expand Down Expand Up @@ -36,7 +36,6 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="FluentAssertions" Version="7.0.0" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Update="NSubstitute" Version="5.3.0" />
<PackageReference Update="xunit" Version="2.9.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void ConfigureOtlpOptions_EndpointSpecified()
var options = new OtlpExporterOptions();
new Metrics(settings).ConfigureMetricsOptions(options);

options.Endpoint.Should().Be(endpoint);
Assert.StartsWith(endpoint, options.Endpoint.ToString());

Environment.SetEnvironmentVariable("SPLUNK_REALM", null);
Environment.SetEnvironmentVariable("OTEL_EXPORTER_OTLP_ENDPOINT", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ public class LoggerTests
[Fact]
public void ConstructorDoesNotThrowExceptionWhenReflectionFails()
{
var action = () => new Logger();
action.Should().NotThrow();
_ = new Logger();
}

[Fact]
public void ImplementationDoesNotThrowExceptionWhenReflectionFails()
{
ILogger logger = new Logger();
var action = () => logger.Warning("message");
action.Should().NotThrow();
var logger = new Logger();
logger.Warning("message");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// </copyright>

using System.Collections.Specialized;
using FluentAssertions.Execution;
using OpenTelemetry.Exporter;
using Splunk.OpenTelemetry.AutoInstrumentation.Configuration;
using Splunk.OpenTelemetry.AutoInstrumentation.Logging;
Expand All @@ -38,11 +37,8 @@ public void ConfigureOtlpOptions()
var options = new OtlpExporterOptions();
new Metrics(settings).ConfigureMetricsOptions(options);

using (new AssertionScope())
{
options.Endpoint.Should().Be("https://ingest.my-realm.signalfx.com/v2/datapoint/otlp");
options.Headers.Should().Be("X-Sf-Token=MyToken");
}
Assert.Equal("https://ingest.my-realm.signalfx.com/v2/datapoint/otlp", options.Endpoint.ToString());
Assert.Equal("X-Sf-Token=MyToken", options.Headers);
}

[Theory]
Expand All @@ -62,12 +58,9 @@ public void WhenRealmIsSetRequireAccessToken(string? accessToken)

new Metrics(settings, loggerMock).ConfigureMetricsOptions(options);

using (new AssertionScope())
{
loggerMock.Received(1).Error(Arg.Any<string>());
loggerMock.Received(1).Error(Arg.Any<string>());

options.Endpoint.ToString().Should().NotContain("my-realm");
options.Headers.Should().BeNull();
}
Assert.DoesNotContain("my-realm", options.Endpoint.ToString());
Assert.Null(options.Headers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

using System.Collections.Specialized;
using System.Reflection;
using FluentAssertions.Execution;
using OpenTelemetry.Resources;
using Splunk.OpenTelemetry.AutoInstrumentation.Configuration;

Expand All @@ -40,14 +39,14 @@ public void ConfigureSplunkDistributionVersion()

var resource = resourceBuilder.Build();
var version = typeof(Plugin).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()!.InformationalVersion.Split('+')[0];
using (new AssertionScope())

var expected = new Dictionary<string, object>
{
resource.Attributes.Should().BeEquivalentTo(new Dictionary<string, object>
{
{ "splunk.distro.version", version },
{ "telemetry.distro.name", "splunk-otel-dotnet" },
{ "telemetry.distro.version", version }
});
}
{ "splunk.distro.version", version },
{ "telemetry.distro.name", "splunk-otel-dotnet" },
{ "telemetry.distro.version", version }
};

Assert.Equivalent(expected, resource.Attributes);
}
}
Loading
Loading