Skip to content

Commit b383834

Browse files
authored
Merge branch 'v1' into v1
2 parents 6382642 + 74bd83f commit b383834

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ All the above options can be added to serverless.yml to set default configuratio
6161
```yml
6262
custom:
6363
dynamodb:
64+
# If you only want to use DynamoDB Local in some stages, declare them here
65+
stages:
66+
- dev
6467
start:
6568
port: 8000
6669
inMemory: true

index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ class ServerlessDynamodbLocal {
1010
this.serverless = serverless;
1111
this.service = serverless.service;
1212
this.serverlessLog = serverless.cli.log.bind(serverless.cli);
13-
this.config = this.service.custom && this.service.custom.dynamodb || {};
1413
this.options = options;
1514
this.provider = "aws";
1615
this.commands = {
@@ -100,6 +99,13 @@ class ServerlessDynamodbLocal {
10099
}
101100
};
102101

102+
const stage = this.options.stage || this.service.provider.stage;
103+
if (this.config.stages && !this.config.stages.includes(stage)) {
104+
// don't do anything for this stage
105+
this.hooks = {};
106+
return;
107+
}
108+
103109
this.hooks = {
104110
"dynamodb:migrate:migrateHandler": this.migrateHandler.bind(this),
105111
"dynamodb:seed:seedHandler": this.seedHandler.bind(this),
@@ -112,13 +118,13 @@ class ServerlessDynamodbLocal {
112118
}
113119

114120
get port() {
115-
const config = this.config;
121+
const config = this.service.custom && this.service.custom.dynamodb || {};
116122
const port = _.get(config, "start.port", 8000);
117123
return port;
118124
}
119125

120126
get host() {
121-
const config = this.config;
127+
const config = this.service.custom && this.service.custom.dynamodb || {};
122128
const host = _.get(config, "start.host", "localhost");
123129
return host;
124130
}
@@ -128,7 +134,7 @@ class ServerlessDynamodbLocal {
128134

129135
if(options && options.online){
130136
this.serverlessLog("Connecting to online tables...");
131-
if (!options.region) {
137+
if (!options.region) {
132138
throw new Error("please specify the region");
133139
}
134140
dynamoOptions = {
@@ -158,7 +164,7 @@ class ServerlessDynamodbLocal {
158164
}
159165

160166
seedHandler() {
161-
const options = this.options;
167+
const options = this.options;
162168
const dynamodb = this.dynamodbOptions(options);
163169

164170
return BbPromise.each(this.seedSources, (source) => {
@@ -183,7 +189,7 @@ class ServerlessDynamodbLocal {
183189
}
184190

185191
startHandler() {
186-
const config = this.config;
192+
const config = this.service.custom && this.service.custom.dynamodb || {};
187193
const options = _.merge({
188194
sharedDb: this.options.sharedDb || true
189195
},
@@ -279,6 +285,9 @@ class ServerlessDynamodbLocal {
279285
migration.SSESpecification.Enabled = migration.SSESpecification.SSEEnabled;
280286
delete migration.SSESpecification.SSEEnabled;
281287
}
288+
if (migration.PointInTimeRecoverySpecification) {
289+
delete migration.PointInTimeRecoverySpecification;
290+
}
282291
if (migration.Tags) {
283292
delete migration.Tags;
284293
}

test/indexTest.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ const expect = require("chai").expect;
66
const should = require("should");
77
const aws = require ("aws-sdk");
88
const seeder = require("../src/seeder.js");
9-
const dataApp = require("../index.js");
9+
const Plugin = require("../index.js");
10+
11+
const serverlessMock = require("./serverlessMock");
1012

1113
describe("Port function",function(){
1214
it("Port should return number",function(){
13-
let myport = dataApp.prototype.port;
14-
assert(typeof myport, "number");
15+
let service = new Plugin(serverlessMock, {});
16+
assert(typeof service.port, "number");
1517
});
1618

1719
it("Port value should be >= 0 and < 65536",function(done){
18-
http.get(`http://localhost:${dataApp.prototype.port}/shell/`, function (response) {
20+
let service = new Plugin(serverlessMock, {});
21+
http.get(`http://localhost:${service.port}/shell/`, function (response) {
1922
assert.equal(response.statusCode, 200);
2023
done();
2124
});
@@ -34,29 +37,29 @@ describe("Check the dynamodb function",function(){
3437
});
3538

3639
it("Should be an object",function(){
37-
let dynamoOptions = dataApp.prototype.dynamodbOptions;
40+
let dynamoOptions = Plugin.prototype.dynamodbOptions;
3841
let raw = new aws.DynamoDB(dynamoOptions);
3942
raw.should.be.type("object");
4043
});
4144

4245
it("Should be an object",function(){
43-
let dynamoOptions = dataApp.prototype.dynamodbOptions;
46+
let dynamoOptions = Plugin.prototype.dynamodbOptions;
4447
let doc = new aws.DynamoDB(dynamoOptions);
4548
doc.should.be.type("object");
4649
});
4750
});
4851

4952
describe ("Start handler function",function(){
5053
it ("Should not be null",function(){
51-
let handler = dataApp.prototype.startHandler;
54+
let handler = Plugin.prototype.startHandler;
5255
assert(handler =! null);
5356
});
5457
});
5558

5659

5760
describe ("createTable functon",function(){
5861
it ("Should check as a function",function(){
59-
const tbl = dataApp.prototype.createTable;
62+
const tbl = Plugin.prototype.createTable;
6063
assert.equal(typeof tbl, "function");
6164
});
6265
});

test/serverlessMock.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
service: {},
3+
cli: {
4+
log: () => {}
5+
},
6+
custom: {}
7+
};

0 commit comments

Comments
 (0)