Local test environment

From Izara Wiki
Jump to navigation Jump to search

Overview

Each repository is a micro-service that performs has responsibility for one part of the The Izara Project, although each is meant to be used as part of a network of interconnected micro-services when a single repository is cloned the first level of testing is at the self contained local level.

Unit tests

Most local tests will be unit tests, these tests are built in two ways:

  1. created in the __test__/unit directory for each serverless project in the repository
  2. generated from integration tests defined in the Integration Test Config service

Serverless Local

sets up a local api gateway and lambda functions adds environment variable IS_OFFLINE into Lambda functions

lambdas deployed to a local serverless offline environment are invoked by sending REST request to local API Gateway endpoint good for testing API Gateway config bad: cannot setup test environment (eg mocks) in the Jest code because is a separate environment to the serverless offline environment cannot test individual functions that are not API Gateway triggered

add to app serverless.yml below code only needed where functions and api gateway are deployed not needed in resource (if using sns/sqs offline they might need it)

plugins:
  - serverless-offline

DynamoDB Local

DynamoDB local connection settings are hardcoded, if need to change things like port maybe we can find some hack like local environment variable, rather than polluting serverless.yml etc..

  • thinking if starting multiple services together on local can use the same dynamodb local database, just placing multiple tables in it
  • default is to store data in memory, which gets destroyed each time we stop, if this becomes unmanageable or if we want to maintain state it is possible to save to file
  • to install into a project, in resource dir:
npm install --save-dev serverless-dynamodb-local
  • follow instructions from the projects site, will need to perform below command once per computer, pulls and installs the AWS DynamoDB project from AWS:
sls dynamodb install
  • all resource serverless.yml have below code, used only for DynamoDB local
  • (not sure) we do not migrate or seed here because we want to do that per service (eg in a script), and might have different seeds for different situations
custom:
 dynamodb:
 # If you only want to use DynamoDB Local in some stages, declare them here
   stages:
     - Dev
   start:
     port: 8000
     inMemory: true
     heapInitial: 200m #not sure correct setting, can leave off
     heapMax: 1g #not sure correct setting, can leave off
     migrate: true
     seed: true
   seed:
     default:
       sources:
         - table: ${self:service}${self:provider.stage}Config
           sources: [./__test__/dynamodb_seed_data/default/Config.json]

Working documents

Working documents - Local test environment