Skip to content

Commit

Permalink
formatting and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pinzon committed Feb 12, 2024
1 parent 6ccf482 commit 12d9034
Show file tree
Hide file tree
Showing 7 changed files with 602 additions and 479 deletions.
4 changes: 2 additions & 2 deletions example/service/handler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';
"use strict";

module.exports.hello = (event, context, callback) => {
process.stdout.write(event.Records[0].EventSource);
process.stdout.write(event.Records[0].Sns.Message);
callback(null, { message: 'Hello from SNS!', event });
callback(null, { message: "Hello from SNS!", event });
};
20 changes: 20 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"chai": "^4.1.2",
"chai-string": "^1.4.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"fs-extra": "^7.0.0",
"jasmine": "^3.2.0",
Expand Down
72 changes: 38 additions & 34 deletions spec/helpers/services.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,72 @@
const tempy = require('tempy');
const execSync = require('child_process').execSync;
const YAML = require('json2yaml');
const fs = require('fs-extra');
const path = require('path');
const serverlessExec = path.join(__dirname, '../../node_modules/.bin/serverless');
const packageJson = require('../../package.json')
const rimraf = require('rimraf')
const tempy = require("tempy");
const execSync = require("child_process").execSync;
const YAML = require("json2yaml");
const fs = require("fs-extra");
const path = require("path");
const serverlessExec = path.join(
__dirname,
"../../node_modules/.bin/serverless",
);
const packageJson = require("../../package.json");
const rimraf = require("rimraf");

const debug = false;

const defaultConfig = {
service: 'aws-nodejs',
service: "aws-nodejs",
provider: {
name: 'aws',
runtime: 'nodejs12.x',
lambdaHashingVersion: '20201221',
name: "aws",
runtime: "nodejs12.x",
lambdaHashingVersion: "20201221",
environment: {
LAMBDA_STAGE: '${ssm:/${opt:stage, self:provider.stage}/lambda/common/LAMBDA_STAGE}'
}
LAMBDA_STAGE:
"${ssm:/${opt:stage, self:provider.stage}/lambda/common/LAMBDA_STAGE}",
},
},
plugins: [
'serverless-localstack'
],
plugins: ["serverless-localstack"],
custom: {
localstack: {
host: 'http://localhost',
host: "http://localhost",
debug: debug,
}
},
},
functions: {
hello: {
handler: 'handler.hello'
}
}
handler: "handler.hello",
},
},
};

const installPlugin = (dir) => {
const pluginsDir = path.join(dir, '.serverless_plugins');
const pluginsDir = path.join(dir, ".serverless_plugins");
fs.mkdirsSync(pluginsDir);

execSync(`mkdir -p node_modules`, {cwd: dir});
execSync(`ln -s ${__dirname}/../../ node_modules/${packageJson.name}`, {cwd: dir});
execSync(`mkdir -p node_modules`, { cwd: dir });
execSync(`ln -s ${__dirname}/../../ node_modules/${packageJson.name}`, {
cwd: dir,
});
};

const execServerless = (arguments, dir) => {
const execServerless = (myArguments, dir) => {
process.chdir(dir);

execSync(`${serverlessExec} ${arguments}`, {
stdio: 'inherit',
stderr: 'inherit',
execSync(`${serverlessExec} ${myArguments}`, {
stdio: "inherit",
stderr: "inherit",
env: Object.assign({}, process.env, {
AWS_ACCESS_KEY_ID: 1234,
AWS_SECRET_ACCESS_KEY: 1234,
PATH: process.env.PATH,
SLS_DEBUG: debug ? '*' : ''
})
SLS_DEBUG: debug ? "*" : "",
}),
});
};

exports.createService = (config, dir) => {
dir = dir || tempy.directory();
config = Object.assign({}, defaultConfig, config);

execServerless('create --template aws-nodejs', dir);
execServerless("create --template aws-nodejs", dir);

fs.writeFileSync(`${dir}/serverless.yml`, YAML.stringify(config));
installPlugin(dir);
Expand All @@ -71,9 +75,9 @@ exports.createService = (config, dir) => {
};

exports.deployService = (dir) => {
execServerless('deploy', dir);
execServerless("deploy", dir);
};

exports.removeService = (dir) => {
rimraf.sync(dir)
rimraf.sync(dir);
};
47 changes: 24 additions & 23 deletions spec/integration/integration.spec.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
'use strict';
"use strict";

const services = require('../helpers/services');
const services = require("../helpers/services");

const LONG_TIMEOUT = 30000;
const AWS = require('aws-sdk');
const AWS = require("aws-sdk");

// Set the region and endpoint in the config for LocalStack
AWS.config.update({
region: 'us-east-1',
endpoint: 'http://127.0.0.1:4566'
region: "us-east-1",
endpoint: "http://127.0.0.1:4566",
});
AWS.config.credentials = new AWS.Credentials({
accessKeyId: 'test',
secretAccessKey: 'test',
accessKeyId: "test",
secretAccessKey: "test",
});

const ssm = new AWS.SSM();

const params = {
Name: '/dev/lambda/common/LAMBDA_STAGE',
Type: 'String',
Value: 'my-value',
Overwrite: true
Name: "/dev/lambda/common/LAMBDA_STAGE",
Type: "String",
Value: "my-value",
Overwrite: true,
};

describe('LocalstackPlugin', () => {

beforeEach(
async () => {
await ssm.putParameter(params).promise();
this.service = services.createService({});
describe("LocalstackPlugin", () => {
beforeEach(async () => {
await ssm.putParameter(params).promise();
this.service = services.createService({});
});

afterEach( () => {
afterEach(() => {
services.removeService(this.service);
});

it('should deploy a stack', () => {
services.deployService(this.service);
}, LONG_TIMEOUT);

});
it(
"should deploy a stack",
() => {
services.deployService(this.service);
},
LONG_TIMEOUT,
);
});
Loading

0 comments on commit 12d9034

Please sign in to comment.