Skip to content

Commit

Permalink
add integration tests for migrating from v2 to v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Sid Nutulapati committed Feb 14, 2019
1 parent 7dec136 commit 8db7489
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 5 deletions.
38 changes: 38 additions & 0 deletions test/integration-tests/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const RANDOM_STRING = randomstring.generate({
charset: "alphanumeric",
capitalization: "lowercase",
});
const TEMP_DIR = `~/tmp/domain-manager-test-${RANDOM_STRING}`;

const testCases = [
{
Expand Down Expand Up @@ -277,4 +278,41 @@ describe("Integration Tests", function () { // eslint-disable-line func-names
await utilities.destroyResources(testName, testURL, RANDOM_STRING);
});
});

describe("Migrating from 2.x.x to 3.x.x works", function () { // eslint-disable-line func-names
this.timeout(15 * 60 * 1000); // 15 minutes in milliseconds
const testName = "two-three-migration-default";
const tempDir = "~/tmp/domain-manager-test"
const testURL = `${testName}-${RANDOM_STRING}.${TEST_DOMAIN}`;

before(async () => {
// Perform sequence of commands to replicate basepath mapping issue
// Sleep for a min b/w commands in order to avoid rate limiting.
await utilities.exec(`rm -rf ${tempDir}`);
await utilities.exec(`mkdir -p ${tempDir} && cp -R test/integration-tests/${testName}/. ${tempDir}`);
await utilities.exec(`cd ${tempDir}/ && npm install [email protected]`);
});

it("Creates a basepath mapping", async () => {
await utilities.exec(`cd ${tempDir} && sls create_domain --RANDOM_STRING ${RANDOM_STRING}`);
await utilities.sleep(60);
await utilities.exec(`cd ${tempDir} && sls deploy --RANDOM_STRING ${RANDOM_STRING}`);
await utilities.sleep(60);
// await utilities.exec(`npm link`)
await utilities.exec(`cp -R . ${tempDir}/node_modules/serverless-domain-manager`);
await utilities.exec(`cd ${tempDir} && sls deploy --RANDOM_STRING ${RANDOM_STRING}`);

const basePath = await utilities.getBasePath(testURL);
expect(basePath).to.equal("(none)");
});

after(async () => {
// await utilities.exec(`npm unlink`);
await utilities.exec(`cd ${tempDir} && sls remove --RANDOM_STRING ${RANDOM_STRING}`);
await utilities.sleep(60);
await utilities.exec(`cd ${tempDir} && sls delete_domain --RANDOM_STRING ${RANDOM_STRING}`);
await utilities.sleep(60);
await utilities.exec(`rm -rf ${tempDir}`);
});
});
});
27 changes: 22 additions & 5 deletions test/integration-tests/test-utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,29 @@ function sleep(seconds) {
return new Promise((resolve) => setTimeout(resolve, 1000 * seconds));
}

/**
* Executes given shell command.
* @param cmd shell command to execute
* @returns {Promise<boolean>} Resolves true if successfully executed, else false
*/
async function exec(cmd) {
return new Promise((resolve) => {
shell.exec(`${cmd}`, { silent: false }, (err, stdout, stderr) => {
if (err || stderr) {
return resolve(false);
}
return resolve(true);
});
});
}

/**
* Links current serverless-domain-manager to global node_modules in order to run tests.
* @returns {Promise<boolean>} Resolves true if successfully linked, else false.
*/
async function linkPackages() {
return new Promise((resolve) => {
shell.exec("npm link serverless-domain-manager", { silent: true }, (err, stdout, stderr) => {
shell.exec("npm link serverless-domain-manager", { silent: false }, (err, stdout, stderr) => {
if (err || stderr) {
return resolve(false);
}
Expand Down Expand Up @@ -119,7 +135,7 @@ async function getBasePath(url) {
*/
function slsCreateDomain(folderName, domainIdentifier) {
return new Promise((resolve) => {
shell.exec(`cd 'test/integration-tests/${folderName}' && sls create_domain --RANDOM_STRING ${domainIdentifier}`, { silent: true }, (err, stdout, stderr) => {
shell.exec(`cd 'test/integration-tests/${folderName}' && sls create_domain --RANDOM_STRING ${domainIdentifier}`, { silent: false }, (err, stdout, stderr) => {
if (err || stderr) {
return resolve(false);
}
Expand All @@ -136,7 +152,7 @@ function slsCreateDomain(folderName, domainIdentifier) {
*/
function slsDeploy(folderName, domainIdentifier) {
return new Promise((resolve) => {
shell.exec(`cd 'test/integration-tests/${folderName}' && sls deploy --RANDOM_STRING ${domainIdentifier}`, { silent: true }, (err, stdout, stderr) => {
shell.exec(`cd 'test/integration-tests/${folderName}' && sls deploy --RANDOM_STRING ${domainIdentifier}`, { silent: false }, (err, stdout, stderr) => {
if (err || stderr) {
return resolve(false);
}
Expand Down Expand Up @@ -205,7 +221,7 @@ async function verifyDnsPropogation(url, enabled) {
*/
function slsDeleteDomain(folderName, domainIdentifier) {
return new Promise((resolve) => {
shell.exec(`cd 'test/integration-tests/${folderName}' && sls delete_domain --RANDOM_STRING ${domainIdentifier}`, { silent: true }, (err, stdout, stderr) => {
shell.exec(`cd 'test/integration-tests/${folderName}' && sls delete_domain --RANDOM_STRING ${domainIdentifier}`, { silent: false }, (err, stdout, stderr) => {
if (err || stderr) {
return resolve(false);
}
Expand All @@ -222,7 +238,7 @@ function slsDeleteDomain(folderName, domainIdentifier) {
*/
function slsRemove(folderName, domainIdentifier) {
return new Promise((resolve) => {
shell.exec(`cd 'test/integration-tests/${folderName}' && sls remove --RANDOM_STRING ${domainIdentifier}`, { silent: true }, (err, stdout, stderr) => {
shell.exec(`cd 'test/integration-tests/${folderName}' && sls remove --RANDOM_STRING ${domainIdentifier}`, { silent: false }, (err, stdout, stderr) => {
if (err || stderr) {
return resolve(false);
}
Expand Down Expand Up @@ -312,6 +328,7 @@ module.exports = {
curlUrl,
createResources,
destroyResources,
exec,
verifyDnsPropogation,
dnsLookup,
slsCreateDomain,
Expand Down
16 changes: 16 additions & 0 deletions test/integration-tests/two-three-migration-default/handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";

module.exports.helloWorld = (event, context, callback) => {
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*", // Required for CORS support to work
},
body: JSON.stringify({
message: "Go Serverless v1.0! Your function executed successfully!",
input: event,
}),
};

callback(null, response);
};
19 changes: 19 additions & 0 deletions test/integration-tests/two-three-migration-default/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Migrating from version 2 to version 3
service: two-three-migration-default
provider:
name: aws
runtime: nodejs6.10
region: us-west-2
functions:
helloWorld:
handler: handler.helloWorld
events:
- http:
path: hello-world
method: get
cors: true
plugins:
- serverless-domain-manager
custom:
customDomain:
domainName: two-three-migration-default-${opt:RANDOM_STRING}.${env:TEST_DOMAIN}

0 comments on commit 8db7489

Please sign in to comment.