Skip to content

Commit c2fe0d8

Browse files
authored
download test-jar for Lambda integration tests with make init-testlibs (localstack#5054)
1 parent f985044 commit c2fe0d8

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ jobs:
7070
docker pull -q lambci/lambda:20191117-provided
7171
docker pull -q lambci/lambda:java8
7272
docker pull -q lambci/lambda:python3.8
73+
- run:
74+
name: Initialize Test Libraries
75+
command: make init-testlibs
7376
- run:
7477
name: Test docker client
7578
environment:

localstack/services/install.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@
118118
)
119119
TERRAFORM_BIN = os.path.join(dirs.static_libs, f"terraform-{TERRAFORM_VERSION}", "terraform")
120120

121+
# Java Test Jar Download (used for tests)
122+
TEST_LAMBDA_JAVA = os.path.join(config.dirs.var_libs, "localstack-utils-tests.jar")
123+
MAVEN_BASE_URL = "https://repo.maven.apache.org/maven2"
124+
TEST_LAMBDA_JAR_URL = "{url}/cloud/localstack/{name}/{version}/{name}-{version}-tests.jar".format(
125+
version=LOCALSTACK_MAVEN_VERSION, url=MAVEN_BASE_URL, name="localstack-utils"
126+
)
127+
121128

122129
def get_elasticsearch_install_version(version: str) -> str:
123130
from localstack.services.es import versions
@@ -407,6 +414,13 @@ def install_lambda_java_libs():
407414
download(URL_LOCALSTACK_FAT_JAR, INSTALL_PATH_LOCALSTACK_FAT_JAR)
408415

409416

417+
def install_lambda_java_testlibs():
418+
# Download the LocalStack Utils Test jar file from the maven repo
419+
if not os.path.exists(TEST_LAMBDA_JAVA):
420+
mkdir(os.path.dirname(TEST_LAMBDA_JAVA))
421+
download(TEST_LAMBDA_JAR_URL, TEST_LAMBDA_JAVA)
422+
423+
410424
def install_go_lambda_runtime():
411425
if os.path.isfile(GO_LAMBDA_RUNTIME):
412426
return
@@ -622,6 +636,7 @@ def main():
622636
if sys.argv[1] in ("libs", "testlibs"):
623637
# Install additional libraries for testing
624638
install_amazon_kinesis_client_libs()
639+
install_lambda_java_testlibs()
625640
print("Done.")
626641

627642

tests/integration/test_lambda.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@
1212
from botocore.exceptions import ClientError
1313

1414
from localstack import config
15-
from localstack.constants import (
16-
LAMBDA_TEST_ROLE,
17-
LOCALSTACK_MAVEN_VERSION,
18-
LOCALSTACK_ROOT_FOLDER,
19-
TEST_AWS_ACCOUNT_ID,
20-
)
15+
from localstack.constants import LAMBDA_TEST_ROLE, TEST_AWS_ACCOUNT_ID
2116
from localstack.services.apigateway.helpers import gateway_request_url
2217
from localstack.services.awslambda import lambda_api, lambda_executors
2318
from localstack.services.awslambda.lambda_api import (
@@ -45,14 +40,14 @@
4540
from localstack.services.install import (
4641
GO_RUNTIME_VERSION,
4742
INSTALL_PATH_LOCALSTACK_FAT_JAR,
43+
TEST_LAMBDA_JAVA,
4844
download_and_extract,
4945
)
5046
from localstack.utils import testutil
5147
from localstack.utils.aws import aws_stack
5248
from localstack.utils.aws.aws_stack import lambda_function_arn
5349
from localstack.utils.common import (
5450
cp_r,
55-
download,
5651
get_arch,
5752
get_free_tcp_port,
5853
get_os,
@@ -88,9 +83,6 @@
8883
TEST_LAMBDA_DOTNETCORE2 = os.path.join(THIS_FOLDER, "lambdas", "dotnetcore2", "dotnetcore2.zip")
8984
TEST_LAMBDA_DOTNETCORE31 = os.path.join(THIS_FOLDER, "lambdas", "dotnetcore31", "dotnetcore31.zip")
9085
TEST_LAMBDA_CUSTOM_RUNTIME = os.path.join(THIS_FOLDER, "lambdas", "custom-runtime")
91-
TEST_LAMBDA_JAVA = os.path.join(
92-
LOCALSTACK_ROOT_FOLDER, "localstack", "infra", "localstack-utils-tests.jar"
93-
)
9486
TEST_LAMBDA_JAVA_WITH_LIB = os.path.join(
9587
THIS_FOLDER, "lambdas", "java", "lambda_echo", "lambda-function-with-lib-0.0.1.jar"
9688
)
@@ -134,12 +126,7 @@
134126
TEST_SNS_TOPIC_NAME = "sns-topic-1"
135127
TEST_STAGE_NAME = "testing"
136128

137-
MAVEN_BASE_URL = "https://repo.maven.apache.org/maven2"
138-
139129
TEST_GOLANG_LAMBDA_URL_TEMPLATE = "https://github.com/localstack/awslamba-go-runtime/releases/download/v{version}/example-handler-{os}-{arch}.tar.gz"
140-
TEST_LAMBDA_JAR_URL = "{url}/cloud/localstack/{name}/{version}/{name}-{version}-tests.jar".format(
141-
version=LOCALSTACK_MAVEN_VERSION, url=MAVEN_BASE_URL, name="localstack-utils"
142-
)
143130

144131
TEST_LAMBDA_LIBS = [
145132
"localstack",
@@ -1725,12 +1712,8 @@ class TestJavaRuntimes(LambdaTestBase):
17251712
def setUpClass(cls):
17261713
cls.lambda_client = aws_stack.connect_to_service("lambda")
17271714

1728-
# deploy lambda - Java
1729-
if not os.path.exists(TEST_LAMBDA_JAVA):
1730-
mkdir(os.path.dirname(TEST_LAMBDA_JAVA))
1731-
download(TEST_LAMBDA_JAR_URL, TEST_LAMBDA_JAVA)
1732-
17331715
# deploy Lambda - default handler
1716+
# The TEST_LAMBDA_JAVA jar file is downloaded with `make init-testlibs`.
17341717
cls.test_java_jar = load_file(TEST_LAMBDA_JAVA, mode="rb")
17351718
zip_dir = new_tmp_dir()
17361719
zip_lib_dir = os.path.join(zip_dir, "lib")

0 commit comments

Comments
 (0)