Skip to content

Commit cfd582b

Browse files
authored
Integration test (#68)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced integration tests for health and ping endpoints. - **Chores** - Updated CI/CD pipeline with a new executor for improved Docker caching and integration testing. - Modified GitHub release creation steps for enhanced automation. - **Refactor** - Updated Dockerfile for optimized application startup. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c87729b commit cfd582b

File tree

7 files changed

+384
-40
lines changed

7 files changed

+384
-40
lines changed

.circleci/config.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ executors:
88
python:
99
docker:
1010
- image: cimg/python:3.12.2
11+
python-machine:
12+
machine:
13+
docker_layer_caching: true
14+
image: ubuntu-2204:edge
1115
defaults:
1216
docker_publish: &docker_publish
1317
image: bsstudio/bss-web-file-api
@@ -34,30 +38,39 @@ jobs:
3438
- run: poetry run black . --check
3539
- run: poetry run pylint src
3640
- run: poetry run mypy -p src
37-
github_release:
38-
docker:
39-
- image: cimg/base:stable
40-
steps:
41-
- checkout
42-
- github-cli/install:
43-
version: 2.43.1
44-
- github-cli/setup:
45-
version: 2.43.1
46-
- run: gh release create << pipeline.git.tag >> -t << pipeline.git.tag >> --generate-notes
4741
coverage:
4842
executor: python
4943
steps:
5044
- checkout
5145
- python/install-packages:
5246
pkg-manager: poetry
5347
- run: |
54-
poetry run pytest --cov=src \
48+
poetry run pytest tests --cov=src \
5549
--cov-fail-under=100 \
5650
--cov-report=html \
5751
--cov-report json
5852
- codecov/upload
5953
- store_artifacts:
6054
path: htmlcov
55+
integration:
56+
executor: python-machine
57+
steps:
58+
- checkout
59+
- python/install-packages:
60+
pkg-manager: poetry
61+
pre-install-steps:
62+
- run: pip install poetry
63+
- run: poetry run pytest tests-int
64+
github_release:
65+
docker:
66+
- image: cimg/base:stable
67+
steps:
68+
- checkout
69+
- github-cli/install:
70+
version: 2.43.1
71+
- github-cli/setup:
72+
version: 2.43.1
73+
- run: gh release create << pipeline.git.tag >> -t << pipeline.git.tag >> --generate-notes
6174
workflows:
6275
Build:
6376
jobs:
@@ -68,8 +81,10 @@ workflows:
6881
- python/test:
6982
name: Unit tests
7083
pkg-manager: poetry
71-
test-tool: pytest
84+
test-tool-args: tests
7285
version: 3.12.2
86+
- integration:
87+
name: Integration tests
7388
- docker/hadolint:
7489
name: Lint Dockerfile
7590
- docker/publish:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ RUN pip install --no-cache-dir ./wheels/*
4444

4545
COPY ./src ./src
4646

47-
CMD ["uvicorn", "src.bss_web_file_server.main:app", "--host", "0.0.0.0", "--port", "80"]
47+
CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "80"]
4848
EXPOSE 80
4949
LABEL org.opencontainers.image.source="https://github.com/BSStudio/bss-web-file-api"
5050
LABEL org.opencontainers.image.description="BSS Web file API"

docker-compose.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@ services:
66
ports:
77
- "80"
88
environment:
9-
SERVER_BASE_PATH: /assets
9+
SERVER_BASE_PATH: /home/nonroot/assets
1010
healthcheck:
11-
test: "wget --tries=1 --no-verbose -qO- http://localhost:80/health | grep -q UP"
12-
start_period: 5s
11+
test: python -c "import requests, sys; sys.exit(0 if 'UP' in requests.get('http://localhost/health').text else 1)"
12+
start_period: 2s
1313
interval: 10s
1414
timeout: 5s
1515
retries: 5
16-
volumes:
17-
- assets:/assets
18-
volumes:
19-
assets:

poetry.lock

Lines changed: 307 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@ readme = "README.md"
66
package-mode = false
77

88
[tool.poetry.dependencies]
9-
python = "^3.12"
109
fastapi = {version="0.110.0", extras=["all"]}
11-
uvicorn = {version = "0.29.0", extras = ["standard"]}
1210
pillow = "10.2.0"
1311
pillow-avif-plugin = "1.4.3"
12+
python = "^3.12"
1413
# used for UploadFile
1514
python-multipart = "0.0.9"
15+
requests = "2.31.0"
16+
uvicorn = {version = "0.29.0", extras = ["standard"]}
1617

1718
[tool.poetry.group.dev.dependencies]
1819
black = "24.3.0"
19-
pre-commit = "3.6.2"
20-
pylint = "3.1.0"
2120
isort = "5.13.2"
22-
types-Pillow = "10.2.0.20240311"
2321
mypy = "1.9.0"
22+
pylint = "3.1.0"
23+
pre-commit = "3.6.2"
24+
types-Pillow = "10.2.0.20240311"
2425

2526
[tool.poetry.group.test.dependencies]
26-
httpx = "^0.27.0"
27-
pytest = "^8.0.0"
28-
pytest-mock = "^3.10.0"
29-
pytest-cov = "^4.1.0"
27+
pytest = "8.0.0"
28+
pytest-cov = "4.1.0"
29+
pytest-mock = "3.10.0"
30+
testcontainers = "4.1.1"
3031

3132
[tool.isort]
3233
profile = "black"

tests-int/__init__.py

Whitespace-only changes.

tests-int/test_health.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import os
2+
3+
import pytest
4+
import requests
5+
from testcontainers.compose import DockerCompose
6+
7+
8+
@pytest.fixture(scope="session")
9+
def compose():
10+
print("Starting compose")
11+
compose = DockerCompose(
12+
context=os.getcwd(),
13+
compose_file_name="docker-compose.yml",
14+
build=True,
15+
wait=True,
16+
)
17+
compose.start()
18+
yield compose
19+
compose.stop()
20+
21+
22+
def test_health(compose: DockerCompose):
23+
host = compose.get_service_host("app")
24+
port = compose.get_service_port("app", 80)
25+
assert "Application startup complete." in compose.get_logs("app")[0]
26+
response = requests.get(f"http://{host}:{port}/health")
27+
assert response.status_code == 200
28+
assert response.text == "UP"
29+
30+
31+
def test_ping(compose: DockerCompose):
32+
host = compose.get_service_host("app")
33+
port = compose.get_service_port("app", 80)
34+
response = requests.get(f"http://{host}:{port}/ping")
35+
assert response.status_code == 200
36+
assert response.text == "PONG"

0 commit comments

Comments
 (0)