lambda integration tests - test to show that environment config has an effect (#28815)
This commit is contained in:
parent
d871964aca
commit
140ea7f5ff
2 changed files with 53 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def handler(event, context):
|
def handler(event, context):
|
||||||
|
@ -17,7 +18,16 @@ def handler(event, context):
|
||||||
|
|
||||||
name = event["name"]
|
name = event["name"]
|
||||||
|
|
||||||
return {"message": "hello " + name}
|
# we can use environment variables as part of the configuration of the lambda
|
||||||
|
# which can change the behaviour of the lambda without needing a new upload
|
||||||
|
|
||||||
|
extra = os.environ.get("EXTRA_MESSAGE")
|
||||||
|
if extra is not None and len(extra) > 0:
|
||||||
|
greeting = "hello {0}. {1}".format(name, extra)
|
||||||
|
else:
|
||||||
|
greeting = "hello " + name
|
||||||
|
|
||||||
|
return {"message": greeting}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -185,12 +185,53 @@
|
||||||
dead_letter_arn:
|
dead_letter_arn:
|
||||||
register: result
|
register: result
|
||||||
|
|
||||||
- name: assert lambda was updated as expected
|
- name: assert lambda remains as before
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
- 'not result|failed'
|
- 'not result|failed'
|
||||||
- 'result.changed == False'
|
- 'result.changed == False'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
- name: test putting an environment variable changes lambda
|
||||||
|
lambda:
|
||||||
|
name: "{{lambda_function_name}}"
|
||||||
|
runtime: "python2.7"
|
||||||
|
handler: "mini_lambda.handler"
|
||||||
|
role: "ansible_lambda_role"
|
||||||
|
ec2_region: '{{ec2_region}}'
|
||||||
|
ec2_access_key: '{{ec2_access_key}}'
|
||||||
|
ec2_secret_key: '{{ec2_secret_key}}'
|
||||||
|
security_token: '{{security_token}}'
|
||||||
|
zip_file: "{{zip_res.dest}}"
|
||||||
|
environment_variables:
|
||||||
|
EXTRA_MESSAGE: "I think you are great!!"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert lambda upload succeeded
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'not result|failed'
|
||||||
|
- 'result.changed == True'
|
||||||
|
|
||||||
|
- name: test lambda works
|
||||||
|
execute_lambda:
|
||||||
|
name: "{{lambda_function_name}}"
|
||||||
|
payload:
|
||||||
|
name: "Mr Ansible Tests"
|
||||||
|
ec2_region: '{{ec2_region}}'
|
||||||
|
ec2_access_key: '{{ec2_access_key}}'
|
||||||
|
ec2_secret_key: '{{ec2_secret_key}}'
|
||||||
|
security_token: '{{security_token}}'
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert lambda manages to respond as expected
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- 'not result|failed'
|
||||||
|
- 'result.result.output.message == "hello Mr Ansible Tests. I think you are great!!"'
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
- name: test state=present triggering a network exception due to bad url
|
- name: test state=present triggering a network exception due to bad url
|
||||||
lambda:
|
lambda:
|
||||||
|
|
Loading…
Reference in a new issue