Skip to content

Commit 9c41656

Browse files
authored
Add integration test via localstack (#941)
1 parent 99224de commit 9c41656

File tree

3 files changed

+75
-7
lines changed

3 files changed

+75
-7
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
initialize: start-docker
44
start-docker:
5-
docker pull amazon/dynamodb-local
6-
docker start async_aws_dynamodb || docker run -d -p 8000:8000 --name async_aws_dynamodb amazon/dynamodb-local
5+
docker start async_aws_localstack && exit 0 || \
6+
docker start async_aws_localstack-dynamodb && exit 0 || \
7+
docker pull localstack/localstack && \
8+
docker run -d -p 4575:4566 -e SERVICES=dynamodb -v /var/run/docker.sock:/var/run/docker.sock --name async_aws_localstack-dynamodb localstack/localstack && \
9+
docker run --rm --link async_aws_localstack-dynamodb:localstack martin/wait -c localstack:4566
710

811
test: initialize
912
./vendor/bin/simple-phpunit
1013

1114
clean: stop-docker
1215
stop-docker:
13-
docker stop async_aws_dynamodb || true
16+
docker stop async_aws_localstack-dynamodb || true

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"ext-json": "*",
1717
"async-aws/core": "^1.2"
1818
},
19+
"conflict": {
20+
"symfony/http-client": "<4.4.16,<5.1.7"
21+
},
1922
"extra": {
2023
"branch-alias": {
2124
"dev-master": "1.1-dev"

tests/Integration/DynamoDbClientTest.php

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use AsyncAws\DynamoDb\Input\DescribeTableInput;
1616
use AsyncAws\DynamoDb\Input\GetItemInput;
1717
use AsyncAws\DynamoDb\Input\ListTablesInput;
18+
use AsyncAws\DynamoDb\Input\PutItemInput;
1819
use AsyncAws\DynamoDb\Input\QueryInput;
1920
use AsyncAws\DynamoDb\Input\ScanInput;
2021
use AsyncAws\DynamoDb\Input\UpdateItemInput;
@@ -191,7 +192,32 @@ public function testBatchGetItem(): void
191192

192193
public function testCreateTable(): void
193194
{
194-
self::markTestSkipped('This is tested in setUp()');
195+
$client = $this->getClient();
196+
197+
$input = new CreateTableInput([
198+
'TableName' => 'demo',
199+
'AttributeDefinitions' => [
200+
new AttributeDefinition(['AttributeName' => 'ForumName', 'AttributeType' => 'S']),
201+
],
202+
'KeySchema' => [
203+
new KeySchemaElement(['AttributeName' => 'ForumName', 'KeyType' => KeyType::HASH]),
204+
],
205+
'ProvisionedThroughput' => new ProvisionedThroughput([
206+
'ReadCapacityUnits' => 5,
207+
'WriteCapacityUnits' => 5,
208+
]),
209+
]);
210+
211+
$result = $client->createTable($input);
212+
$result->resolve();
213+
214+
try {
215+
self::assertSame('arn:aws:dynamodb:us-east-1:000000000000:table/demo', $result->getTableDescription()->getTableArn());
216+
self::assertSame('0', $result->getTableDescription()->getItemCount());
217+
self::assertTrue($client->tableExists(['TableName' => 'demo'])->isSuccess());
218+
} finally {
219+
$this->getClient()->deleteTable(['TableName' => 'demo']);
220+
}
195221
}
196222

197223
public function testDeleteItem(): void
@@ -216,7 +242,28 @@ public function testDeleteItem(): void
216242

217243
public function testDeleteTable(): void
218244
{
219-
self::markTestSkipped('This is tested in tearDown()');
245+
$client = $this->getClient();
246+
247+
$input = new CreateTableInput([
248+
'TableName' => 'demo',
249+
'AttributeDefinitions' => [
250+
new AttributeDefinition(['AttributeName' => 'ForumName', 'AttributeType' => 'S']),
251+
],
252+
'KeySchema' => [
253+
new KeySchemaElement(['AttributeName' => 'ForumName', 'KeyType' => KeyType::HASH]),
254+
],
255+
'ProvisionedThroughput' => new ProvisionedThroughput([
256+
'ReadCapacityUnits' => 5,
257+
'WriteCapacityUnits' => 5,
258+
]),
259+
]);
260+
261+
$client->createTable($input);
262+
263+
$result = $client->deleteTable(['TableName' => 'demo']);
264+
$result->resolve();
265+
266+
self::assertFalse($client->tableExists(['TableName' => 'demo'])->isSuccess());
220267
}
221268

222269
public function testDescribeTable(): void
@@ -267,7 +314,22 @@ public function testListTables(): void
267314

268315
public function testPutItem(): void
269316
{
270-
self::markTestSkipped('This is tested in setUp()');
317+
$client = $this->getClient();
318+
319+
$input = new PutItemInput([
320+
'TableName' => $this->tableName,
321+
'Item' => [
322+
'LastPostDateTime' => ['S' => '201303190422'],
323+
'Tags' => ['SS' => ['Update', 'Multiple Items', 'HelpMe']],
324+
'ForumName' => ['S' => 'Amazon DynamoDB'],
325+
'Message' => ['S' => 'I want to update multiple items in a single call. What\'s the best way to do that?'],
326+
'Subject' => ['S' => 'How do I update multiple items?'],
327+
'LastPostedBy' => ['S' => '[email protected]'],
328+
],
329+
]);
330+
331+
$result = $client->putItem($input);
332+
self::assertSame(1.0, $result->getConsumedCapacity()->getCapacityUnits());
271333
}
272334

273335
public function testQuery(): void
@@ -413,7 +475,7 @@ private function getClient(): DynamoDbClient
413475
}
414476

415477
return $this->client = new DynamoDbClient([
416-
'endpoint' => 'http://localhost:8000',
478+
'endpoint' => 'http://localhost:4575',
417479
], new Credentials('aws_id', 'aws_secret'));
418480
}
419481
}

0 commit comments

Comments
 (0)