dynamodb-test
v0.3.0
Published
Create and destroy DynamoDB and Dynalite tables for use in tape tests
Downloads
34
Maintainers
Readme
dynamodb-test
Create and destroy DynamoDB and Dynalite tables for use in tape tests
Simple example
var tape = require('tape');
var tableDef = require('./table-definition.json');
var dynamodb = require('dynamodb-test')(tape, 'my-tests', tableDef, 'us-east-1');
dynamodb.test('my test', function(assert) {
// starts your table, then runs your assertions, then purges your table
assert.end();
});
// Clean up the table when you're done with it
dynamodb.delete();
API
var dynamodb = require('dynamodb-test')(tape, projectName, tableDef, [region], [port])
Configure the dynamodb
object by providing your own tape
object, an arbitrary name for your project, and the JSON object that defines the table's schema. Optionally, you may specify a region. If you do, tests will be run against a live DynamoDB table in that region. If you don't, tests will be run against a local instance of dynalite. If you specify a port, dynalite will listen on it, otherwise it will use 4567.
** var dynamodb = require('dynamodb-test').fixedName(tape, tableName, tableDef)**
To configure a dynalite test runner with a fixed table name.
dynamodb.dynamo
An instance of AWS.DynamoDB configured to query your test endpoint (live or dynalite).
dynamodb.dyno
A dyno instance configured to work against your test endpoint.
dynamodb.tableName
A randomly generated name of the table created for your tests.
dynamodb.tableDef
The table definition you provided, with TableName
modified to match dynamodb.tableName
dynamodb.start()
Creates the table
dynamodb.delete()
Deletes the table.
dynamodb.load(fixtures)
By providing an array of dyno-style features, dynamodb-test can load them into your test database.
dynamodb.empty()
Empties all records from your table, for consistency across tests.
dynamodb.test(testName, [fixtures], callback)
A wrapper around tape that:
- creates your table or empties it if it already exists
- optionally, loads fixtures that you provide
- runs your tests by providing an
assertion
object to yourcallback
function - empties your table
dynamodb.close()
If you're working in a mock test environment, use this call to shut down dynalite.