Skip to content

Commit

Permalink
Merge pull request #29 from byu-oit/debug
Browse files Browse the repository at this point in the history
added more debug statements to lambda function code
  • Loading branch information
yoshutch authored Apr 2, 2021
2 parents 8a17d34 + d8b9ca4 commit bcf619e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This lambda function will tell CodeDeploy if the tests pass or fail.

```hcl
module "postman_test_lambda" {
source = "github.com/byu-oit/terraform-aws-postman-test-lambda?ref=v3.0.0"
source = "github.com/byu-oit/terraform-aws-postman-test-lambda?ref=v3.0.1"
app_name = "simple-example"
postman_collections = [
{
Expand Down Expand Up @@ -85,7 +85,7 @@ selecting your collection/environment and clicking on the info icon.

```hcl
module "postman_test_lambda" {
source = "github.com/byu-oit/terraform-aws-postman-test-lambda?ref=v3.0.0"
source = "github.com/byu-oit/terraform-aws-postman-test-lambda?ref=v3.0.1"
app_name = "from-postman-api-example"
postman_collections = [
{
Expand Down
Binary file modified lambda/dist/function.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion lambda/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "postman-test-lambda",
"version": "2.0.0",
"version": "3.0.1",
"description": "Lambda function that runs postman collection tests",
"repository": {
"type": "git",
Expand Down
23 changes: 18 additions & 5 deletions lambda/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ const s3 = new AWS.S3({ apiVersion: '2014-10-06', region: 'us-west-2' })
const tmpDir = process.env.TMP_DIR || os.tmpdir()

exports.handler = async function (event, context) {
console.log(event)
console.log('event', event)
const deploymentId = event.DeploymentId
const combinedRunner = event.Combined
if (deploymentId) {
console.log(`After postman tests are complete, this will update the CodeDeploy deployment ${deploymentId}.`)
} else if (combinedRunner) {
console.log(`After postman tests are complete, this will return a pass/fail to the combined runner: ${combinedRunner}`)
} else {
console.log('No DeploymentId found in event, this will execute the postman tests and then exit.')
}

// Workaround for CodeDeploy bug.
// Give the ALB 10 seconds to make sure the test TG has switched to the new code.
const timer = sleep(10000)
Expand Down Expand Up @@ -42,9 +52,10 @@ exports.handler = async function (event, context) {
}
}
}
// finish the 10 second timer before trying to run the postman tests as well as finish downloading any files
// make sure all files are downloaded and we wait for 10 seconds before executing postman tests
await Promise.all(promises)

console.log('starting postman tests ...')
if (!error) {
// no need to run tests if files weren't downloaded correctly
for (const each of postmanList) {
Expand All @@ -56,10 +67,9 @@ exports.handler = async function (event, context) {
}
}
}
console.log('postman tests finished')
}

const deploymentId = event.DeploymentId
const combinedRunner = event.Combined
if (deploymentId) {
console.log('starting to update CodeDeploy lifecycle event hook status...')
const params = {
Expand Down Expand Up @@ -149,7 +159,10 @@ async function runTest (postmanCollection, postmanEnvironment) {

function sleep (ms) {
console.log('started sleep timer')
return new Promise(resolve => setTimeout(resolve, ms))
return new Promise(resolve => setTimeout(args => {
console.log('ended sleep timer')
resolve()
}, ms))
}

// exports.handler({}, {})

0 comments on commit bcf619e

Please sign in to comment.