Skip to content

Commit 73695ce

Browse files
authored
refactor(test): allow linux integ test to run in github action (#8386)
* integ * remove cred * fix multiple failures * nit * nit2 * nit3 * nit4 * nit o * use test account * direct * retry * nit * nit * fix multiple stuff * move get cred after init * test * use maven version * use original function * nit * check ruby issue * ruby * ruby 3.4 * maven * nit * enable java 21 * finalize sync test * test build integ test * split container/no container tests * fix * fix container * use -k correctly * k * k2 * kk * split container/non-container integ test * revert test * make sure in buildcmd, all container test has container in its name * fix test issues * disk space * tweak disk usage * rest * nit * n * n * use secret * secr * n * run all test * m * schedule * test * fix remote test event failure * address feedback * Update test_remote_test_event.py
1 parent 88e3dd1 commit 73695ce

File tree

20 files changed

+632
-106
lines changed

20 files changed

+632
-106
lines changed

.github/workflows/integration-tests.yml

Lines changed: 423 additions & 0 deletions
Large diffs are not rendered by default.

samcli/commands/remote/invoke/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def do_cli(
173173
event = lambda_test_event["json"]
174174
LOG.debug("Remote event contents: %s", event)
175175
metadata = lambda_test_event["metadata"]
176-
if "invocationType" in metadata:
176+
if "invocationType" in metadata and metadata["invocationType"] is not None:
177177
parameter.setdefault("InvocationType", metadata["invocationType"])
178178
elif test_event_name:
179179
LOG.info("Note: remote event is only supported for AWS Lambda Function resource.")

samcli/lib/utils/name_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
MIN_ARN_PARTS = 5 # Minimum parts for a valid ARN structure
1313

1414
LAMBDA_FUNCTION_NAME_PATTERN = (
15-
r"^(arn:[^:]+:lambda:[^:]*:\d{12}:function:|\d{12}:function:)?[a-zA-Z0-9-_\.]+(:[\w$-]+)?$"
15+
r"^(arn:[^:]+:lambda:[^:]*:\d{12}:function:|\d{12}:function:)?[a-zA-Z0-9-_\.\[\]]+(:[\w$-]+)?$"
1616
)
1717

1818

tests/get_testing_resources.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import json
77
import os
8+
import sys
89

910
import boto3
1011
from boto3.session import Session
@@ -16,7 +17,8 @@
1617

1718

1819
def main():
19-
env_vars = get_testing_credentials()
20+
skip_role_deletion = len(sys.argv) > 1 and sys.argv[1] == "skip_role_deletion"
21+
env_vars = get_testing_credentials(skip_role_deletion)
2022
# Assume testing account credential in order to access managed test resource stack
2123
test_session = Session(
2224
aws_access_key_id=env_vars["accessKeyID"],
@@ -37,7 +39,7 @@ def get_managed_test_resource_outputs(session: Session):
3739
return outputs_dict
3840

3941

40-
def get_testing_credentials():
42+
def get_testing_credentials(skip_role_deletion=False):
4143
lambda_arn = os.environ["CREDENTIAL_DISTRIBUTION_LAMBDA_ARN"]
4244
# Max attempts to 0 so that boto3 will not invoke multiple times
4345
lambda_client = boto3.client(
@@ -49,7 +51,14 @@ def get_testing_credentials():
4951
),
5052
region_name="us-west-2",
5153
)
52-
response = lambda_client.invoke(FunctionName=lambda_arn)
54+
55+
# Prepare payload if skip_role_deletion is True
56+
if skip_role_deletion:
57+
payload_data = json.dumps({"skip_role_deletion": True})
58+
response = lambda_client.invoke(FunctionName=lambda_arn, Payload=payload_data)
59+
else:
60+
response = lambda_client.invoke(FunctionName=lambda_arn)
61+
5362
payload = json.loads(response["Payload"].read())
5463
if response.get("FunctionError"):
5564
raise ValueError(f"Failed to get credential. {payload['errorType']}")

tests/integration/buildcmd/build_integ_base.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
import logging
99
import json
10+
from datetime import datetime, timezone
1011
from typing import Optional
1112
from unittest import TestCase
1213

@@ -36,6 +37,27 @@
3637
LOG = logging.getLogger(__name__)
3738

3839

40+
def show_container_in_test_name(testcase_func, param_num, param):
41+
"""
42+
Generates a custom name for parameterized test cases.
43+
Adds '_in_container' suffix when any parameter contains 'container' in its string representation.
44+
"""
45+
# Get the base test name
46+
base_name = f"{testcase_func.__name__}_{param_num}"
47+
48+
# Check if any parameter contains "container" in its string representation
49+
for arg in param.args:
50+
if isinstance(arg, str) and "container" in arg.lower():
51+
base_name += "_in_container"
52+
break
53+
elif arg is True: # Also check for boolean True which might indicate use_container
54+
# Check if this might be a use_container parameter by position
55+
# This is a fallback for cases where True is used instead of "use_container"
56+
continue
57+
58+
return base_name
59+
60+
3961
class BuildIntegBase(TestCase):
4062
template: Optional[str] = "template.yaml"
4163

@@ -543,6 +565,12 @@ def _test_with_go(self, runtime, code_uri, mode, relative_path, architecture=Non
543565
newenv["GOPROXY"] = "direct"
544566
newenv["GOPATH"] = str(self.working_dir)
545567

568+
# Build with musl target to avoid glibc compatibility issues
569+
# This ensures the binary works in the Lambda execution environment
570+
newenv["GOOS"] = "linux"
571+
newenv["GOARCH"] = "arm64" if architecture == ARM64 else "amd64"
572+
newenv["CGO_ENABLED"] = "0"
573+
546574
run_command(cmdlist, cwd=self.working_dir, env=newenv)
547575

548576
self._verify_built_artifact(
@@ -638,7 +666,7 @@ def _test_with_building_java(
638666
osutils.convert_to_unix_line_ending(os.path.join(self.test_data_path, self.USING_GRADLEW_PATH, "gradlew"))
639667
# Use shorter timeout in GitHub Actions to fail faster;
640668
# Putting 1800 because Windows Canary Instances takes longer
641-
timeout = 90 if os.environ.get("GITHUB_ACTIONS") else 1800
669+
timeout = 1800 if os.environ.get("BY_CANARY") else 180
642670
run_command(cmdlist, cwd=self.working_dir, timeout=timeout)
643671

644672
self._verify_built_artifact(

0 commit comments

Comments
 (0)