Writing tests using local dynamodb using mocha

I am using Dynamodb for the api service I am writing. I started writing tests, and I found that there is no command (or query) that destroys all the "elements" in the table. I use vogels to access dynamodb.

I usually clean the table before each test. How to do this if there is no single command (or query) that deletes all the elements in the table?

If I delete each item one by one, the tests start running before all the items are deleted.

+4
source share
1 answer

Operation CRUD is atomic in DynamoDB. The API is not available to delete all elements of the DynamoDB table.

Solution 1:

The best recommended solution is to delete the table and recreate it.

Solution 2:

Use batchWriteItem with DeleteRequest to delete multiple items at a time. The maximum number of packet write requests is 25 items.

Wait: -

After executing the deletion table, wait until the resource is unavailable. Similarly, after executing the create table, you need to wait until the resource is available.

var params = {
  TableName: 'STRING_VALUE' /* required */
};
dynamodb.waitFor('tableNotExists', params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

Expects the NotExists table to declare, periodically invoking DynamoDB.describeTable () operations every 20 seconds (with more than 25 times).

+1
source

Source: https://habr.com/ru/post/1681929/


All Articles