|
| 1 | +"""Unit tests for run_package_pipeline.""" |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from tests.golden.harness import run_build_pipeline, run_package_pipeline |
| 8 | + |
| 9 | +CASES_ROOT = Path(__file__).parent / "templates" |
| 10 | + |
| 11 | + |
| 12 | +def test_package_sam_case_rewrites_code_to_s3_uri(): |
| 13 | + case = CASES_ROOT / "sam_resources" / "serverless_function_zip" |
| 14 | + build_out = run_build_pipeline(case / "template.yaml", language_extensions=False) |
| 15 | + pkg_out = run_package_pipeline(case / "template.yaml", build_out) |
| 16 | + code = pkg_out["Resources"]["HelloFunction"]["Properties"]["Code"] |
| 17 | + assert isinstance(code, dict) # CFN Lambda Code becomes S3Bucket/S3Key dict |
| 18 | + s3_uri_field = code.get("S3Bucket") or code.get("ImageUri") or "" |
| 19 | + assert s3_uri_field == "golden-bucket" |
| 20 | + |
| 21 | + |
| 22 | +def test_package_le_case_rewrites_each_expanded_codeuri(): |
| 23 | + case = CASES_ROOT / "language_extensions" / "foreach_static_zip" |
| 24 | + build_out = run_build_pipeline(case / "template.yaml", language_extensions=True) |
| 25 | + pkg_out = run_package_pipeline(case / "template.yaml", build_out) |
| 26 | + for fn_id in ("AlphaFunction", "BetaFunction"): |
| 27 | + code = pkg_out["Resources"][fn_id]["Properties"]["Code"] |
| 28 | + assert isinstance(code, dict) |
| 29 | + assert code.get("S3Bucket") == "golden-bucket" |
| 30 | + |
| 31 | + |
| 32 | +def test_package_cfn_case_rewrites_raw_code_path(): |
| 33 | + case = CASES_ROOT / "packageable_resources" / "lambda_function_zip" |
| 34 | + build_out = run_build_pipeline(case / "template.yaml", language_extensions=False) |
| 35 | + pkg_out = run_package_pipeline(case / "template.yaml", build_out) |
| 36 | + code = pkg_out["Resources"]["HelloFunction"]["Properties"]["Code"] |
| 37 | + assert isinstance(code, dict) |
| 38 | + assert code.get("S3Bucket") == "golden-bucket" |
| 39 | + |
| 40 | + |
| 41 | +def test_package_is_deterministic(): |
| 42 | + """Same input produces same output across runs.""" |
| 43 | + case = CASES_ROOT / "sam_resources" / "serverless_function_zip" |
| 44 | + build_out = run_build_pipeline(case / "template.yaml", language_extensions=False) |
| 45 | + a = run_package_pipeline(case / "template.yaml", build_out) |
| 46 | + b = run_package_pipeline(case / "template.yaml", build_out) |
| 47 | + assert a == b |
0 commit comments