Skip to content

Commit

Permalink
Rework integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
godu committed Apr 27, 2019
1 parent 7a10ad6 commit fc9658a
Show file tree
Hide file tree
Showing 42 changed files with 477 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ coverage

# OSX
.DS_Store

# Python
*.pyc
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js

node_js:
- "10"
- "8"
Expand All @@ -7,8 +8,9 @@ sudo: required
services:
- docker

cache: npm

addons:
chrome: stable
apt:
sources:
- ubuntu-toolchain-r-test
Expand Down
30 changes: 18 additions & 12 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,39 @@
"type": "node",
"request": "launch",
"name": "SQS",
"program": "${workspaceFolder}/node_modules/.bin/serverless",
"cwd": "${workspaceFolder}/packages/serverless-offline-sqs/example",
"program": "${workspaceFolder}/packages/serverless-offline-sqs-integration/node_modules/.bin/serverless",
"cwd": "${workspaceFolder}/packages/serverless-offline-sqs-integration",
"env": {
"PATH": "${env:PATH}:${workspaceFolder}/packages/serverless-offline-sqs-integration/node_modules/.bin"
},
"args": [
"offline",
"start"
"offline"
]
},
{
"type": "node",
"request": "launch",
"name": "DynamoDB Streams",
"program": "${workspaceFolder}/node_modules/.bin/serverless",
"cwd": "${workspaceFolder}/packages/serverless-offline-dynamodb-streams/example",
"program": "${workspaceFolder}/packages/serverless-offline-dynamodb-streams-integration/node_modules/.bin/serverless",
"cwd": "${workspaceFolder}/packages/serverless-offline-dynamodb-streams-integration",
"env": {
"PATH": "${env:PATH}:${workspaceFolder}/packages/serverless-offline-dynamodb-streams-integration/node_modules/.bin"
},
"args": [
"offline",
"start"
"offline"
]
},
{
"type": "node",
"request": "launch",
"name": "Kinesis",
"program": "${workspaceFolder}/node_modules/.bin/serverless",
"cwd": "${workspaceFolder}/packages/serverless-offline-kinesis/example",
"program": "${workspaceFolder}/packages/serverless-offline-kinesis-integration/node_modules/.bin/serverless",
"cwd": "${workspaceFolder}/packages/serverless-offline-kinesis-integration",
"env": {
"PATH": "${env:PATH}:${workspaceFolder}/packages/serverless-offline-kinesis-integration/node_modules/.bin"
},
"args": [
"offline",
"start"
"offline"
]
}
]
Expand Down
6 changes: 6 additions & 0 deletions packages/dynamodb-streams-readable/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ function DynamoDBStreamReadable(client, arn, options) {
pending--;

if (err) {
if (err.name === 'TrimmedDataAccessException') {
return describeStream(function(e) {
if (e) return checkpoint.emit('error', e);
read(callback);
});
}
return callback(err);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/serverless-apigateway-access-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"author": "Adrien Becchis @Coorpacademy (https://github.com/AdrieanKhisbe)",
"license": "MIT",
"dependencies": {
"aws-sdk": "^2.443.0",
"aws-sdk": "^2.444.0",
"lodash": "^4.17.11"
},
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ do
--provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 \
--stream-specification StreamEnabled=true,StreamViewType=NEW_AND_OLD_IMAGES \
> /dev/null 2> /dev/null
done
done &
done &
done

wait

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ services:
- dynamodb
entrypoint: sh
volumes:
- ./example/:/project
- ./example/create-tables.sh:/project/create-tables.sh:ro
- ./:/project
- ./create-tables.sh:/project/create-tables.sh:ro
environment:
- AWS_ACCESS_KEY_ID=local
- AWS_SECRET_ACCESS_KEY=local
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import json

def handler(event, context):
print(event)
return

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "serverless-offline-dynamodb-streams-integration",
"private": true,
"scripts": {
"start": "sls offline",
"pretest": "docker-compose stop dynamodb && docker-compose rm -f dynamodb && docker-compose run dynamodb-create",
"test": "node ./test.js"
},
"dependencies": {
"aws-sdk": "^2.444.0",
"figures": "^3.0.0",
"lodash": "^4.17.11",
"serverless": "^1.41.1",
"serverless-offline": "^4.9.4",
"serverless-offline-dynamodb-streams": "1.5.1",
"signal-exit": "^3.0.2"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ functions:
Fn::GetAtt:
- MyThirdTable
- Arn
myPythonHandler:
runtime: python2.7
handler: handler.handler
events:
- stream:
type: dynamodb
arn:
Expand Down
79 changes: 79 additions & 0 deletions packages/serverless-offline-dynamodb-streams-integration/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* eslint-disable unicorn/no-process-exit */
const {Writable} = require('stream');
const {spawn} = require('child_process');
const onExit = require('signal-exit');
const {DynamoDB} = require('aws-sdk');

const client = new DynamoDB({
region: 'eu-west-1',
accessKeyId: 'local',
secretAccessKey: 'local',
endpoint: 'http://localhost:8000'
});

const putItems = () => {
return Promise.all([
client
.putItem({
Item: {id: {S: 'MyFirstId'}},
TableName: 'MyFirstTable'
})
.promise(),
client
.putItem({
Item: {id: {S: 'MySecondId'}},
TableName: 'MySecondTable'
})
.promise(),
client
.putItem({
Item: {id: {S: 'MyThirdId'}},
TableName: 'MyThirdTable'
})
.promise(),
client
.putItem({
Item: {id: {S: 'MyFourthId'}},
TableName: 'MyFourthTable'
})
.promise()
]);
};

const serverless = spawn('sls', ['offline'], {
stdio: ['pipe', 'pipe', 'pipe'],
cwd: __dirname
});

serverless.stdout.pipe(
new Writable({
write(chunk, enc, cb) {
const output = chunk.toString();

if (/Offline listening on/.test(output)) {
putItems();
}

this.count = (this.count || 0) + (output.match(/\[✔\]/g) || []).length;
if (this.count === 4) serverless.kill();
cb();
}
})
);

serverless.stdout.on('data', data => {
console.log(data.toString());
});

serverless.stderr.on('data', data => {
console.error(data.toString());
process.exit(1);
});

serverless.on('close', code => {
process.exit(code);
});

onExit((code, signal) => {
if (signal) serverless.kill(signal);
});
2 changes: 1 addition & 1 deletion packages/serverless-offline-dynamodb-streams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ plugins:
- serverless-offline
```

[See example](./example/README.md)
[See example](../serverless-offline-dynamodb-streams-integration/README.md)

## Configure

Expand Down

This file was deleted.

10 changes: 0 additions & 10 deletions packages/serverless-offline-dynamodb-streams/example/test.sh

This file was deleted.

5 changes: 1 addition & 4 deletions packages/serverless-offline-dynamodb-streams/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
],
"author": "godu",
"license": "MIT",
"scripts": {
"test": "cd example && npm test"
},
"dependencies": {
"aws-sdk": "^2.443.0",
"aws-sdk": "^2.444.0",
"dynamodb-streams-readable": "^1.0.3",
"figures": "^3.0.0",
"lodash": "^4.17.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ do
--stream-name ${STREAM} \
--shard-count 1 \
> /dev/null 2> /dev/null
done
done &
done &
done

wait

Expand Down
Loading

0 comments on commit fc9658a

Please sign in to comment.