Skip to content

Commit f5ac705

Browse files
committed
test: add e2e tests for API gateway
1 parent 101b68c commit f5ac705

File tree

14 files changed

+292
-22
lines changed

14 files changed

+292
-22
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
name: Integration tests with Pytest
3+
4+
on:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
integration-gateway:
15+
runs-on: self-hosted
16+
container: nikolaik/python-nodejs:python3.10-nodejs18
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- uses: ./.github/actions/setup-poetry
21+
22+
- name: Test with pytest
23+
working-directory: tests
24+
run: poetry run pytest integrations/gateway -n $(nproc --all)
25+
env:
26+
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
27+
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}
28+
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY }}
29+
API_GATEWAY_S3_BUCKET: ${{ secrets.API_GATEWAY_S3_BUCKET }}

.github/workflows/pytest-integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: Integration tests with Pytest
2+
name: API Gateway integration tests with Pytest
33

44
on:
55
push:
@@ -28,7 +28,7 @@ jobs:
2828

2929
- name: Test with pytest
3030
working-directory: tests
31-
run: poetry run pytest integrations -n $(nproc --all)
31+
run: poetry run pytest integrations -n $(nproc --all) --ignore=integrations/gateway
3232
env:
3333
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_DEFAULT_ORGANIZATION_ID }}
3434
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY }}

poetry.lock

Lines changed: 71 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pytest-xdist = "^3.1.0"
5151
pylint = "^2.15.10"
5252
pylint-per-file-ignores = "^1.1.0"
5353
responses = ">=0.22,<0.24"
54+
boto3 = "^1.26.97"
5455

5556
[tool.poetry.group.doc]
5657
optional = true
@@ -72,7 +73,7 @@ disable = "missing-module-docstring"
7273
# Commented Black formatted code.
7374
max-line-length = 89
7475
# Short and common names. e is commonly used for exceptions.
75-
good-names = "i,fp,e"
76+
good-names = "e,fp,i,s,s3"
7677
# Classes with a single responsibility are fine.
7778
min-public-methods = 1
7879

scw_serverless/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def deploy(
9898
backend: Literal["api", "serverless"],
9999
single_source: bool,
100100
gateway_url: Optional[str] = None,
101-
gayeway_api_key: Optional[str] = None,
101+
gateway_api_key: Optional[str] = None,
102102
profile_name: Optional[str] = None,
103103
secret_key: Optional[str] = None,
104104
project_id: Optional[str] = None,
@@ -143,7 +143,7 @@ def deploy(
143143
raise RuntimeError(
144144
"Your application requires an API Gateway but no gateway URL was provided"
145145
)
146-
if not gayeway_api_key:
146+
if not gateway_api_key:
147147
raise RuntimeError(
148148
"Your application requires an API Gateway but "
149149
+ "no gateway API key was provided to manage routes"
@@ -152,7 +152,7 @@ def deploy(
152152
manager = GatewayManager(
153153
app_instance=app_instance,
154154
gateway_url=gateway_url,
155-
gateway_api_key=gayeway_api_key,
155+
gateway_api_key=gateway_api_key,
156156
sdk_client=client,
157157
)
158158
manager.update_routes()

scw_serverless/dependencies_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pathlib
33
import subprocess
44
import sys
5+
from importlib.metadata import version
56
from typing import Optional
67

78
from scw_serverless.logger import get_logger
@@ -71,7 +72,8 @@ def _check_for_scw_serverless(self):
7172
not self.pkg_path.exists()
7273
or not self.pkg_path.joinpath(__package__).exists()
7374
):
74-
self._run_pip_install("scw_serverless")
75+
# Installs the current version with pip
76+
self._run_pip_install(f"{__package__}=={version(__package__)}")
7577

7678
def _run_pip_install(self, *args: str):
7779
python_path = sys.executable
@@ -84,6 +86,7 @@ def _run_pip_install(self, *args: str):
8486
"--target",
8587
str(self.pkg_path.resolve()),
8688
]
89+
print(command)
8790
try:
8891
subprocess.run(
8992
command,

scw_serverless/version.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/app_fixtures/routed_functions.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@
33
from scw_serverless.app import Serverless
44

55
NAMESPACE_NAME = "integration-tests-gateway"
6+
MESSAGES = {
7+
"/health": "I'm fine!",
8+
"/messages": "Could not find any message",
9+
}
610

711
app = Serverless(NAMESPACE_NAME)
812

913

1014
@app.get(url="/health")
1115
def health(_event: dict[str, Any], _context: dict[str, Any]):
12-
return "I'm fine!"
16+
return MESSAGES["/health"]
1317

1418

1519
@app.get(url="/messages")
1620
def get_messages(_event: dict[str, Any], _context: dict[str, Any]):
17-
return "Could not find any message"
21+
return MESSAGES["/messages"]
1822

1923

2024
@app.post(url="/messages/new")

tests/constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99

1010
COLD_START_TIMEOUT = 20
1111

12+
API_GATEWAY_IMAGE_TAG = "0.0.5"
13+
API_GATEWAY_IMAGE = (
14+
f"registry.hub.docker.com/shillakerscw/scw-sls-gw:{API_GATEWAY_IMAGE_TAG}"
15+
)
16+
API_GATEWAY_MEMORY_LIMIT = 2048
17+
API_GATEWAY_S3_REGION = REGION_FR_PAR
18+
API_GATEWAY_S3_BUCKET_ENDPOINT = f"https://s3.{REGION_FR_PAR}.scw.cloud"
19+
API_GATEWAY_S3_BUCKET = os.getenv("API_GATEWAY_S3_BUCKET")
20+
1221
TESTS_DIR = os.path.realpath(os.path.dirname(__file__))
1322

1423
APP_FIXTURES_PATH = Path(TESTS_DIR, "app_fixtures")

tests/integrations/deploy/test_api_backend.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# pylint: disable=unused-import,redefined-outer-name # fixture
22

3+
import time
4+
35
import scaleway.function.v1beta1 as sdk
46

57
from tests import constants
68
from tests.app_fixtures import app, app_updated, multiple_functions
7-
from tests.integrations.deploy.deploy_wrapper import run_deploy_command
9+
from tests.integrations.deploy_wrapper import run_deploy_command
810
from tests.integrations.project_fixture import scaleway_project # noqa
911
from tests.integrations.utils import create_client, trigger_function
1012

@@ -50,9 +52,8 @@ def test_integration_deploy_existing_function(scaleway_project: str): # noqa
5052
app_path=constants.APP_FIXTURES_PATH / "app_updated.py",
5153
)
5254

53-
import time
54-
55-
time.sleep(60)
55+
# TODO?: delete this
56+
time.sleep(30)
5657

5758
# Check updated message content
5859
resp = trigger_function(url)

0 commit comments

Comments
 (0)