Skip to content

Commit ce2cf9d

Browse files
timtim
authored andcommitted
clean up directories. Refactor - inject endpoints when setting credentials rather than after the service is created. Otherwise credentials are validated against the remote endpoint.
1 parent 0d83b5e commit ce2cf9d

File tree

12 files changed

+97
-158
lines changed

12 files changed

+97
-158
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
before_install:
1+
before_install:
2+
- docker-compose pull
3+
- docker-compose run localstack
24
- npm install --ignore-scripts
35
language: node_js
46
node_js:
57
- "5.10"
68
- "4.4"
9+
services:
10+
- docker
11+
12+
before_install:
13+
script:
14+
echo "127.0.0.1 localstack" | sudo tee -a /etc/hosts
15+
npm test
16+
npm run test_integration

docker-compose.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,18 @@ services:
1313
- AWS_SESSION_TOKEN
1414
- AWS_SECURITY_TOKEN
1515
localstack:
16-
image: atlassianlabs/localstack:latest
16+
image: atlassianlabs/localstack
1717
ports:
18-
- "4567-4578"
19-
- "8080"
18+
- "4567-4582:4567-4582"
19+
- "8080:8080"
20+
environment:
21+
# Only start a subset of services required for testing.
22+
- SERVICES=s3,sns,sqs,apigateway,lambda,dynamodb,dynamodbstreams,cloudformation
23+
# - DEBUG=${DEBUG- }
24+
# - DATA_DIR=${DATA_DIR- }
25+
# - LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
26+
# - KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
27+
# - DOCKER_HOST=unix:///var/run/docker.sock
28+
# volumes:
29+
# - "${TMP_DIR:-/tmp/localstack}:${TMP_DIR:-/tmp/localstack}"
30+
# - "/var/run/docker.sock:/var/run/docker.sock"
File renamed without changes.

spec/support/service/serverless.yml renamed to example/service/serverless.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ provider:
77
plugins:
88
- serverless-plugin-localstack
99

10+
custom:
11+
localstack:
12+
endpoint: localstack_endpoints.json
13+
1014
functions:
1115
hello:
1216
handler: handler.hello

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"name": "serverless-plugin-localstack",
33
"version": "0.0.1",
44
"description": "",
5-
"main": "index.js",
5+
"main": "src/index.js",
66
"scripts": {
77
"lint": "eslint .",
88
"lint-fix": "eslint . --fix",
99
"test": "jasmine",
10-
"test_integration": "npm pack && TMPDIR=/tmp jasmine --config=spec/support/jasmine_integration.json",
10+
"test_integration": "TMPDIR=/tmp jasmine --config=spec/support/jasmine_integration.json",
1111
"test:watch": "nodemon -L -i spec/integrate ./node_modules/.bin/jasmine",
1212
"test:cover": "jasmine --coverage"
1313
},

spec/integrate/utils/index.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,27 @@ const installPlugin = (tmpDir) => {
3232
'.serverless_plugins');
3333
const myPluginDir=path.join(pluginsDir,
3434
`${packageJson.name}`);
35-
const rootPlugin=path.join(__dirname, '..', '..', '..', `${packageJson.name}-${packageJson.version}.tgz`)
35+
const rootPluginDir=path.join(__dirname, '..', '..', '..')
3636

3737

3838
fse.mkdirsSync(pluginsDir)
39+
3940
// TODO - use nodejs
4041
// TODO - copy directories locally from node_modules
41-
execSync(`tar -xz -C ${pluginsDir} -f ${rootPlugin}`)
42-
execSync(`mv ${pluginsDir}/package ${pluginsDir}/${packageJson.name}`)
43-
for (dependency in packageJson.dependencies){
44-
moduleDir=path.join('..','..','..','node_modules','dependency');
45-
fse.copySync(dependency,path.join(myPluginDir,'node_modules'), { clobber: true, preserveTimestamps: true });
46-
}
42+
console.log(`ln -s ${rootPluginDir} ${myPluginDir}`)
43+
execSync(`ln -s ${rootPluginDir} ${myPluginDir}`)
44+
45+
// execSync(`tar -xz -C ${pluginsDir} -f ${rootPlugin}`)
46+
// execSync(`mv ${pluginsDir}/package ${pluginsDir}/${packageJson.name}`)
47+
// for (dependency in packageJson.dependencies){
48+
// moduleDir=path.join('..','..','..','node_modules','dependency');
49+
// fse.copySync(dependency,path.join(myPluginDir,'node_modules'), { clobber: true, preserveTimestamps: true });
50+
// }
4751

4852
console.log(`Plugin installed to: ${myPluginDir}`)
53+
// throw 'wobbly'
4954

50-
fse.copySync(rootPlugin,path.join(pluginDir, 'index.js'), { clobber: true, preserveTimestamps: true });
55+
// fse.copySync(rootPlugin,path.join(pluginDir, 'index.js'), { clobber: true, preserveTimestamps: true });
5156
};
5257

5358
module.exports = {
@@ -201,8 +206,8 @@ module.exports = {
201206
return logsString;
202207
},
203208

204-
deployService(args='') {
205-
execSync(`${serverlessExec} deploy ${args}`, { stdio: 'inherit' });
209+
deployService() {
210+
execSync(`${serverlessExec} deploy`, { stdio: 'inherit' });
206211
},
207212

208213
removeService() {

spec/integrate/utils/index.spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ describe('Test utils', () => {
2424
});
2525
});
2626

27+
describe('#createTestService()', () => {
28+
it('should copy the localstack_endpoints.json', ()=> {
29+
fail('TODO')
30+
});
31+
});
32+
2733
describe('Localstack Support', ()=> {
2834

2935
const snsEndpoint="http://localstack:4575"
@@ -88,6 +94,7 @@ describe('Test utils', () => {
8894
});
8995

9096
describe("Lambda", () => {
97+
// TODO require
9198
const lambdaEndpoint='http://localstack:4574';
9299
const endpoint=path.join(__dirname, 'localstack_endpoints.json')
93100
beforeAll((done) => {
@@ -98,7 +105,7 @@ describe('Test utils', () => {
98105

99106
describe("#deployService()", ()=> {
100107
it("should create a local function", ()=> {
101-
testUtils.deployService(`--endpoint file://${endpoint}`)
108+
testUtils.deployService()
102109
.then( (response) => {
103110
return request(lambdaEndpoint + '/2015-03-31/functions/')
104111
})

spec/support/localstack_endpoints.json

Lines changed: 0 additions & 129 deletions
This file was deleted.

spec/unit/example_localstack_endpoints.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ describe("example/localstack_endpoints.json", () => {
2323
'SQS',
2424
]
2525
services.forEach( (service) => {
26-
2726
expect(example_endpoints[service]).to.be.a('string', `${service} is not defined`)
2827
});
2928
});

0 commit comments

Comments
 (0)