forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(s3-deployment): restore lambda tests (aws#12220)
The change in aws#12129 accidentally deleted the unit tests for the s3-deployment lambda function. This change restores them. Since tests are written in python, run them inside a docker image derived from public.ecr.aws/lambda/python. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Elad Ben-Israel
authored
Dec 24, 2020
1 parent
63bc98f
commit a4934be
Showing
6 changed files
with
552 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { spawnSync } from 'child_process'; | ||
import * as path from 'path'; | ||
|
||
test('lambda python pytest', () => { | ||
const result = spawnSync(path.join(__dirname, 'lambda', 'test.sh'), { stdio: 'inherit' }); | ||
expect(result.status).toBe(0); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/@aws-cdk/aws-s3-deployment/test/lambda/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
FROM public.ecr.aws/lambda/python:latest | ||
|
||
# add everything to /opt/awscli (this is where `aws` is executed from) | ||
ADD . /opt/awscli | ||
|
||
# install boto3, which is available on Lambda | ||
RUN pip3 install boto3 | ||
|
||
# run tests | ||
WORKDIR /opt/awscli | ||
RUN ["python3", "./test.py"] | ||
|
||
ENTRYPOINT [ "/bin/bash" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env python | ||
#=================================================================================================== | ||
# mock for the "aws" cli | ||
# | ||
# the mock behaves as follows: | ||
# - argvs are going to be written to "aws.out" (one command in each line) | ||
# - if "aws s3 cp" is invoked, the destination will be populated with a test zip file. | ||
# - for "cp" and "sync", "aws.out" argv[4] is replaced by "archive.zip" and "contents.zip" | ||
# becuase the actual value is a full path of a temporary directory | ||
# | ||
import sys | ||
import json | ||
import os | ||
import shutil | ||
|
||
scriptdir=os.path.dirname(os.path.realpath(__file__)) | ||
|
||
# if "cp" is called with a local destination, copy a test zip file to the destination or | ||
if sys.argv[2] == "cp" and not sys.argv[4].startswith("s3://"): | ||
shutil.copyfile(os.path.join(scriptdir, 'test.zip'), sys.argv[4]) | ||
sys.argv[4] = "archive.zip" | ||
|
||
if sys.argv[2] == "sync": | ||
sys.argv[4 if '--delete' in sys.argv else 3] = "contents.zip" | ||
|
||
with open("./aws.out", "a") as myfile: | ||
myfile.write(json.dumps(sys.argv[1:]) + "\n") |
Oops, something went wrong.