Skip to content

Commit

Permalink
fix: ddb account id metric test (#3051)
Browse files Browse the repository at this point in the history
Basically, some e2e tests do not use the latest SDK version and therefore latest changes in the endpoint rule set file are not present there, which makes some of tests depending on those latest changes to fail. In this specific case it failed when checking if an account id was resolved or not in dynamodb, because the endpoint ruleset file did not contain the AccountId parameter. For fixing this I use a custom endpoint provider where the ruleset file contains the needed parameter and rule.
  • Loading branch information
yenfryherrerafeliz authored Dec 18, 2024
1 parent 5a62003 commit 50c70d9
Show file tree
Hide file tree
Showing 5 changed files with 836 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/UserAgentMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Aws\Crypto\MaterialsProvider;
use Aws\Crypto\MaterialsProviderV2;
use Aws\DynamoDb\DynamoDbClient;
use Aws\EndpointV2\EndpointDefinitionProvider;
use Aws\MetricsBuilder;
use Aws\Result;
use Aws\S3\Crypto\S3EncryptionClient;
Expand Down Expand Up @@ -658,7 +659,20 @@ public function testUserAgentCaptureGzipRequestCompressionMetric()
*/
public function testUserAgentCaptureResolvedAccountIdMetric()
{
try {
$ruleSet = $this->getDynamoDBTestRuleSet();
} catch (\Exception $e) {
$this->fail($e->getMessage());
}

$dynamoDbClient = new DynamoDbClient([
'api_provider' => ApiProvider::filesystem(
__DIR__ . '/fixtures/aws_client_test'
),
'endpoint_provider' => new \Aws\EndpointV2\EndpointProviderV2(
$ruleSet,
EndpointDefinitionProvider::getPartitions()
),
'region' => 'us-east-2',
'credentials' => new Credentials(
'foo',
Expand Down Expand Up @@ -686,6 +700,22 @@ public function testUserAgentCaptureResolvedAccountIdMetric()
$dynamoDbClient->listTables();
}

/**
* @throws \Exception
*/
private function getDynamoDBTestRuleSet(): array
{
$baseDir = __DIR__ . '/fixtures/aws_client_test/dynamodb';
$ruleSetFile = $baseDir . '/2012-08-10/endpoint-rule-set-1.json';
if (!file_exists($ruleSetFile)) {
throw new \Exception(
'DynamoDB rule set file does not exist at: ' . $ruleSetFile
);
}

return json_decode(file_get_contents($ruleSetFile), true);
}

/**
* Tests user agent captures the flexible checksum metric.
*
Expand Down
79 changes: 79 additions & 0 deletions tests/fixtures/aws_client_test/dynamodb/2012-08-10/api-2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"version":"2.0",
"metadata":{
"apiVersion":"2012-08-10",
"endpointPrefix":"dynamodb",
"jsonVersion":"1.0",
"protocol":"json",
"protocols":["json"],
"serviceAbbreviation":"DynamoDB",
"serviceFullName":"Amazon DynamoDB",
"serviceId":"DynamoDB",
"signatureVersion":"v4",
"targetPrefix":"DynamoDB_20120810",
"uid":"dynamodb-2012-08-10",
"auth":["aws.auth#sigv4"]
},
"operations": {
"ListTables": {
"name": "ListTables",
"http": {
"method": "POST",
"requestUri": "/"
},
"input": {
"shape": "ListTablesInput"
},
"output": {
"shape": "ListTablesOutput"
},
"errors": [
{
"shape": "InternalServerError"
}
],
"endpointdiscovery": {
}
}
},
"shapes":{
"InternalServerError":{
"type":"structure",
"members":{
"message":{"shape":"ErrorMessage"}
},
"exception":true,
"fault":true
},
"ErrorMessage":{"type":"string"},
"ListTablesInput":{
"type":"structure",
"members":{
"ExclusiveStartTableName":{"shape":"TableName"},
"Limit":{"shape":"ListTablesInputLimit"}
}
},
"ListTablesInputLimit":{
"type":"integer",
"max":100,
"min":1
},
"ListTablesOutput":{
"type":"structure",
"members":{
"TableNames":{"shape":"TableNameList"},
"LastEvaluatedTableName":{"shape":"TableName"}
}
},
"TableName":{
"type":"string",
"max":255,
"min":3,
"pattern":"[a-zA-Z0-9_.-]+"
},
"TableNameList":{
"type":"list",
"member":{"shape":"TableName"}
}
}
}

Large diffs are not rendered by default.

Loading

0 comments on commit 50c70d9

Please sign in to comment.