Skip to content

Commit

Permalink
Container integration tests are working
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Dec 5, 2024
1 parent 5b7ef78 commit 0e20b38
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class ArnBuilder

public ArnBuilder(string partition, string region, string accountId)
{
Partition = partition ?? "";
Region = region ?? "";
AccountId = accountId ?? "";
Partition = partition ?? "aws";
Region = region ?? "(unknown)"; // default to a non-empty string to allow for local testing
AccountId = accountId ?? "(unknown)";
}

public string Build(string service, string resource) => ConstructArn(Partition, service, Region, AccountId, resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ private AmazonDynamoDBClient GetDynamoDBClient()
{
// Set the endpoint URL
ServiceURL = "http://dynamodb:8000", // port must match what is set in docker compose
AuthenticationRegion = "us-west-2",
RegionEndpoint = RegionEndpoint.USWest2
AuthenticationRegion = "us-east-2"
//RegionEndpoint = RegionEndpoint.USEast2 **DO NOT* specify RegionEndpoint for local tests
};

// use plausible (but fake) access key and fake secret key so account id parsing can be tested
AmazonDynamoDBClient client = new AmazonDynamoDBClient("FOOIHSFODNNAEXAMPLE", "MOREGIBBERISH", clientConfig);
var creds = new BasicAWSCredentials("FOOIHSFODNNAEXAMPLE", "MOREGIBBERISH"); // account id will be "520056171328"

AmazonDynamoDBClient client = new AmazonDynamoDBClient(creds, clientConfig);

return client;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public abstract class AwsSdkDynamoDBTestBase : NewRelicIntegrationTest<AwsSdkCon
private readonly string _title = "Ghost";
private readonly string _year = "1990";

private const string _accountId = "520056171328"; // matches the account ID parsed from the fake access key used in AwsSdkDynamoDBExerciser

protected AwsSdkDynamoDBTestBase(AwsSdkContainerDynamoDBTestFixture fixture, ITestOutputHelper output) : base(fixture)
{
_fixture = fixture;
Expand Down Expand Up @@ -68,9 +70,6 @@ protected AwsSdkDynamoDBTestBase(AwsSdkContainerDynamoDBTestFixture fixture, ITe
[Fact]
public void Test()
{
Assert.Equal(0, _fixture.AgentLog.GetWrapperExceptionLineCount());
Assert.Equal(0, _fixture.AgentLog.GetApplicationErrorLineCount());

var metrics = _fixture.AgentLog.GetMetrics().ToList();

var metricScopeBase = "WebTransaction/MVC/AwsSdkDynamoDB/";
Expand Down Expand Up @@ -106,7 +105,31 @@ public void Test()

};

Assertions.MetricsExist(expectedMetrics, metrics);
var expectedAttributes = new Dictionary<string, object> {{ "cloud.resource_id", $"arn:aws:dynamodb:(unknown):{_accountId}:table/{_tableName}" } };

var transactionSample = _fixture.AgentLog.TryGetTransactionSample(createTableScope);
var transactionEvent = _fixture.AgentLog.TryGetTransactionEvent(createTableScope);
var spanEvent = _fixture.AgentLog.TryGetSpanEvent(createTableScope);


Assert.Multiple(
() => Assert.Equal(0, _fixture.AgentLog.GetWrapperExceptionLineCount()),
() => Assert.Equal(0, _fixture.AgentLog.GetApplicationErrorLineCount()),

() => Assert.NotNull(transactionSample),
() => Assert.NotNull(transactionEvent),
() => Assert.NotNull(spanEvent),

() => Assertions.TransactionTraceHasAttributes(expectedAttributes, Agent.Tests.TestSerializationHelpers.Models.TransactionTraceAttributeType.Agent, transactionSample),
() => Assertions.TransactionEventDoesNotHaveAttributes(["cloud.resource_id"], Agent.Tests.TestSerializationHelpers.Models.TransactionEventAttributeType.Agent, transactionEvent),
() => Assertions.SpanEventHasAttributes(expectedAttributes, Agent.Tests.TestSerializationHelpers.Models.SpanEventAttributeType.Agent, spanEvent),

() => Assertions.MetricsExist(expectedMetrics, metrics)
);




}
}

Expand Down

0 comments on commit 0e20b38

Please sign in to comment.