Giter VIP home page Giter VIP logo

testcontainers-dynamodb's Introduction

Testcontainers DynamoDB

Local DynamoDB implementation for https://www.testcontainers.org/

Install

npm i -D testcontainers-dynamodb

Example:

const initDataTest = [
  {
    table: {
      TableName: 'newTable',
      AttributeDefinitions: [
        {
          AttributeName: 'id',
          AttributeType: 'S',
        },
      ],
      KeySchema: [
        {
          AttributeName: 'id',
          KeyType: 'HASH',
        },
      ],
      ProvisionedThroughput: {
        ReadCapacityUnits: 1,
        WriteCapacityUnits: 1,
      },
    },
    items: [
      {
        id: '1',
        data: '222',
      },
      {
        id: '2',
        data: 'abc',
      },
    ],
  },
]

describe('DynamoDB container', () => {
  jest.setTimeout(120000)

  let startedContainer: StartedDynamoDBContainer
  beforeAll(async() => {
    startedContainer = await new DynamoDBContainer().start()
  })

  afterEach(async() => {
    await startedContainer.resetData()
  })

  afterAll(async() => {
    await startedContainer.stop()
  })

  it('should populate db with predefine data', async() => {
    const dynamoClient = startedContainer.createDynamoClient()
    const dynamoDocumentClient = startedContainer.createDocumentClient()
    await startedContainer.resetData(initDataTest)

    const allData = await dynamoDocumentClient.scan({ TableName: 'newTable' }).promise()

    expect(await dynamoClient.listTables().promise()).toEqual({ TableNames: ['emptyTable', 'newTable'] })
    expect(allData.Items).toEqual(initDataTest[0].items)
  })
})

testcontainers-dynamodb's People

Contributors

mielientiev avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

testcontainers-dynamodb's Issues

Should `testcontainers` be a normal (not dev) dependency?

Currently it seems that testcontainers is defined as a devDependency

https://github.com/mielientiev/testcontainers-dynamodb/blob/master/package.json#L40

Would it be more semantically correct to define this as a normal dependency? After all, if testcontainers-dynamodb is itself defined as a devDependency in a package that uses it, all its transitive dependencies will be devDependencies anyway?

I am currently testing out using testcontainers-dynamodb for developing a reusable dynamodb module goldstack/goldstack#12 and given I am using Yarn 2 / Berry, I am getting an error due to testcontainers being defined as devDependency:

    Cannot find module 'testcontainers' from 'C:\Users\Max\repos\goldstack-mega\.yarn\__virtual__\testcontainers-dynamodb-virtual-fe25de8cca\0\cache\testcontainers-dynamodb-npm-1.0.1-02a79f93be-5b2225e74c.zip\node_modules\testcontainers-dynamodb\dist'

    Require stack:
      C:/Users/Max/repos/goldstack-mega/.yarn/__virtual__/testcontainers-dynamodb-virtual-fe25de8cca/0/cache/testcontainers-dynamodb-npm-1.0.1-02a79f93be-5b2225e74c.zip/node_modules/testcontainers-dynamodb/dist/DynamoDBContainer.js
      C:/Users/Max/repos/goldstack-mega/.yarn/__virtual__/testcontainers-dynamodb-virtual-fe25de8cca/0/cache/testcontainers-dynamodb-npm-1.0.1-02a79f93be-5b2225e74c.zip/node_modules/testcontainers-dynamodb/dist/index.js
      C:/Users/Max/repos/goldstack-mega/workspaces/templates-lib/packages/template-dynamodb/src/templateDynamoDBTable.ts
      C:/Users/Max/repos/goldstack-mega/workspaces/templates-lib/packages/template-dynamodb/src/templateDynamoDB.ts
      src/table.ts
      src/table.spec.ts

      at resolveSync (../../../../.yarn/cache/resolve-patch-10355818cd-b63b73ecbb.zip/node_modules/resolve/lib/sync.js:111:15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.