Skip to content

Commit

Permalink
Don't rely on Zip output being identical across platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Aug 11, 2023
1 parent 232f919 commit 7638c02
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 4 additions & 2 deletions test.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ rmdir /S /Q temp-persisted-data
docker compose run --rm test setup || goto :exit
:: Sanity check...
docker compose run --rm test verify || goto :exit
docker compose down
docker compose stop
:: Ensure changes were persisted...
docker compose run --rm test verify || goto :exit
docker compose down
docker compose stop

rmdir /S /Q temp-persisted-data

:: Ensure changes from previous runs can still be loaded (test backward-compatibility)...
xcopy test-persisted-data temp-persisted-data /E /I
docker compose run --rm test verify || goto :exit
docker compose stop

docker compose down

:exit
Expand Down
6 changes: 4 additions & 2 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@ sudo rm -rf temp-persisted-data
docker compose run --rm test setup
echo 'Sanity check...'
docker compose run --rm test verify
docker compose down
docker compose stop
echo 'Ensure changes were persisted...'
docker compose run --rm test verify
docker compose down
docker compose stop

sudo rm -rf temp-persisted-data

echo 'Ensure changes from previous runs can still be loaded (test backward-compatibility)...'
cp -r test-persisted-data temp-persisted-data
docker compose run --rm test verify
docker compose stop

docker compose down

echo 'Tests passed!'
10 changes: 5 additions & 5 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ def assert_equal(a, b):
lambda_client = boto3.client("lambda", endpoint_url=endpoint_url)
acm = boto3.client("acm", endpoint_url=endpoint_url)

zipbuf = io.BytesIO()
with zipfile.ZipFile(zipbuf, "w") as zip:
zip.write("lambda/bootstrap", "bootstrap")

cert = open("cert.pem", "r").read()
cert_key = open("key.pem", "r").read()

Expand All @@ -46,6 +42,9 @@ def assert_equal(a, b):

role = iam.create_role(RoleName="test-role", AssumeRolePolicyDocument="{}")

zipbuf = io.BytesIO()
with zipfile.ZipFile(zipbuf, "w") as zip:
zip.write("lambda/bootstrap", "bootstrap")
lambda_client.create_function(
FunctionName="test-lambda",
Role=role.arn,
Expand Down Expand Up @@ -76,7 +75,8 @@ def assert_equal(a, b):
assert_equal(lambda_response["Configuration"].get("Role", None), role.arn)
lambda_code_location = lambda_response["Code"].get("Location", "")
with urllib.request.urlopen(lambda_code_location) as f:
assert_equal(f.read(), zipbuf.getvalue())
with zipfile.ZipFile(io.BytesIO(f.read())) as zip:
assert_equal(zip.read("bootstrap"), open("lambda/bootstrap", "rb").read())
lambda_client.get_waiter("function_active_v2").wait(FunctionName="test-lambda")
lambda_response = lambda_client.invoke(
FunctionName="test-lambda", Payload="hello world"
Expand Down

0 comments on commit 7638c02

Please sign in to comment.