Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test of function to upload Zip to Lambda #309

Merged
merged 7 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,12 +420,12 @@ Lambda.prototype._setRunTimeEnvironmentVars = function (program) {
}
}

Lambda.prototype._uploadExisting = function (lambda, params, cb) {
var request = lambda.updateFunctionCode({
Lambda.prototype._uploadExisting = (lambda, params, cb) => {
const request = lambda.updateFunctionCode({
'FunctionName': params.FunctionName,
'ZipFile': params.Code.ZipFile,
'Publish': params.Publish
}, function (err, data) {
}, (err, data) => {
if (err) {
return cb(err, data)
}
Expand All @@ -442,25 +442,22 @@ Lambda.prototype._uploadExisting = function (lambda, params, cb) {
'Environment': params.Environment,
'DeadLetterConfig': params.DeadLetterConfig,
'TracingConfig': params.TracingConfig
}, function (err, data) {
}, (err, data) => {
return cb(err, data)
})
})

request.on('retry', function (response) {
request.on('retry', (response) => {
console.log(response.error.message)
console.log('=> Retrying')
})

return request
}

Lambda.prototype._uploadNew = function (lambda, params, cb) {
var request = lambda.createFunction(params, function (err, data) {
return cb(err, data)
})

request.on('retry', function (response) {
Lambda.prototype._uploadNew = (lambda, params, cb) => {
const request = lambda.createFunction(params, (err, data) => cb(err, data))
request.on('retry', (response) => {
console.log(response.error.message)
console.log('=> Retrying')
})
Expand Down
60 changes: 40 additions & 20 deletions test/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ const _mockSetting = () => {
callback(null, lambdaMockSettings[method])
})
})

return require('aws-sdk')
}

const _awsRestore = () => {
awsMock.restore('CloudWatchEvents')
awsMock.restore('Lambda')
}

/* global before, after, beforeEach, afterEach, describe, it */
Expand All @@ -105,6 +112,14 @@ describe('lib/main', function () {
this.timeout(60000)
}

let aws = null // mock
let awsLambda = null // mock
before(() => {
aws = _mockSetting()
awsLambda = new aws.Lambda({ apiVersion: '2015-03-31' })
})
after(() => _awsRestore())

beforeEach(function () {
program = Hoek.clone(originalProgram)
})
Expand Down Expand Up @@ -834,25 +849,14 @@ describe('lib/main', function () {
}]
}

let awsLambda = null

before(() => {
fs.writeFileSync(
'event_sources.json',
JSON.stringify(eventSourcesJsonValue)
)
_mockSetting()

awsLambda = new (require('aws-sdk')).Lambda({
apiVersion: '2015-03-31'
})
})

after(() => {
fs.unlinkSync('event_sources.json')
awsMock.restore('CloudWatchEvents')
awsMock.restore('Lambda')
})
after(() => fs.unlinkSync('event_sources.json'))

it('program.eventSourceFile is empty value', (done) => {
program.eventSourceFile = ''
Expand Down Expand Up @@ -935,16 +939,10 @@ describe('lib/main', function () {
'event_sources.json',
JSON.stringify(eventSourcesJsonValue)
)

_mockSetting()
schedule = new ScheduleEvents(require('aws-sdk'))
schedule = new ScheduleEvents(aws)
})

after(() => {
fs.unlinkSync('event_sources.json')
awsMock.restore('CloudWatchEvents')
awsMock.restore('Lambda')
})
after(() => fs.unlinkSync('event_sources.json'))

it('program.eventSourceFile is empty value', (done) => {
program.eventSourceFile = ''
Expand Down Expand Up @@ -985,6 +983,28 @@ describe('lib/main', function () {
})
})

describe('_uploadNew', () => {
it('simple test with mock', (done) => {
const params = lambda._params(program, null)
lambda._uploadNew(awsLambda, params, (err, results) => {
assert.isNull(err)
assert.deepEqual(results, lambdaMockSettings.createFunction)
done()
})
})
})

describe('_uploadExisting', () => {
it('simple test with mock', (done) => {
const params = lambda._params(program, null)
lambda._uploadExisting(awsLambda, params, (err, results) => {
assert.isNull(err)
assert.deepEqual(results, lambdaMockSettings.updateFunctionConfiguration)
done()
})
})
})

describe('check env vars before create sample files', function () {
const filesCreatedBySetup = [
'.env',
Expand Down