Skip to content

Commit

Permalink
More unit tests to increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Jul 10, 2024
1 parent 71dcab0 commit 8a75685
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ public class AgentWrapperApiTests
private TimeSpan? _harvestCycle;

private const string DistributedTraceHeaderName = "newrelic";
private const string DistributedTraceStateHeaderName = "tracestate";
private const string DistributedTraceParentHeaderName = "traceparent";

private const string ReferrerTripId = "referrerTripId";
private const string ReferrerPathHash = "referrerPathHash";
private const string ReferrerTransactionGuid = "referrerTransactionGuid";
Expand Down Expand Up @@ -1064,6 +1067,49 @@ public void TraceMetadata_ShouldReturnValidValues_IfDTConfigIsTrue()
});
}

[Test]
public void GetConfiguredDTHeaders_ShouldReturnEmptyDictionary_IfDTConfigIsFalse()
{
SetupTransaction();

Mock.Arrange(() => _configurationService.Configuration.DistributedTracingEnabled).Returns(false);

var headers = _agent.GetConfiguredDTHeaders();

Assert.That(headers, Is.Empty);
}
[Test]
public void GetConfiguredDTHeaders_ShouldReturnOnlyW3CHeaders_IfExcludeNewrelicHeaderIsTrue()
{
SetupTransaction();

Mock.Arrange(() => _configurationService.Configuration.DistributedTracingEnabled).Returns(true);
Mock.Arrange(() => _configurationService.Configuration.ExcludeNewrelicHeader).Returns(true);

var headers = _agent.GetConfiguredDTHeaders().ToList();

Assert.That(headers, Has.Count.EqualTo(2));
Assert.That(headers, Does.Contain(DistributedTraceParentHeaderName));
Assert.That(headers, Does.Contain(DistributedTraceStateHeaderName));
Assert.That(headers, Does.Not.Contain(DistributedTraceHeaderName));
}
[Test]
public void GetConfiguredDTHeaders_ShouldReturnAllHeaders_IfExcludeNewrelicHeaderIsFalse()
{
SetupTransaction();

Mock.Arrange(() => _configurationService.Configuration.DistributedTracingEnabled).Returns(true);
Mock.Arrange(() => _configurationService.Configuration.ExcludeNewrelicHeader).Returns(false);

var headers = _agent.GetConfiguredDTHeaders().ToList();

Assert.That(headers, Has.Count.EqualTo(3));
Assert.That(headers, Does.Contain(DistributedTraceParentHeaderName));
Assert.That(headers, Does.Contain(DistributedTraceStateHeaderName));
Assert.That(headers, Does.Contain(DistributedTraceHeaderName));
}


#endregion Distributed Trace

#region TraceMetadata
Expand Down

0 comments on commit 8a75685

Please sign in to comment.