Skip to content

Commit ff25f86

Browse files
authored
Merge branch 'v1' into v1
2 parents 7e1cbdf + 7e41861 commit ff25f86

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

README.md

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

index.js

Lines changed: 10 additions & 4 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 = {
@@ -96,6 +95,13 @@ class ServerlessDynamodbLocal {
9695
}
9796
};
9897

98+
const stage = this.options.stage || this.service.provider.stage;
99+
if (this.config.stages && !this.config.stages.includes(stage)) {
100+
// don't do anything for this stage
101+
this.hooks = {};
102+
return;
103+
}
104+
99105
this.hooks = {
100106
"dynamodb:migrate:migrateHandler": this.migrateHandler.bind(this),
101107
"dynamodb:seed:seedHandler": this.seedHandler.bind(this),
@@ -108,13 +114,13 @@ class ServerlessDynamodbLocal {
108114
}
109115

110116
get port() {
111-
const config = this.config;
117+
const config = this.service.custom && this.service.custom.dynamodb || {};
112118
const port = _.get(config, "start.port", 8000);
113119
return port;
114120
}
115121

116122
get host() {
117-
const config = this.config;
123+
const config = this.service.custom && this.service.custom.dynamodb || {};
118124
const host = _.get(config, "start.host", "localhost");
119125
return host;
120126
}
@@ -177,7 +183,7 @@ class ServerlessDynamodbLocal {
177183
}
178184

179185
startHandler() {
180-
const config = this.config;
186+
const config = this.service.custom && this.service.custom.dynamodb || {};
181187
const options = _.merge({
182188
sharedDb: this.options.sharedDb || true
183189
},

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)