Skip to content

Commit 033cab8

Browse files
committed
ci: add unit test for the main app
Signed-off-by: peefy <xpf6677@163.com>
1 parent a7d1159 commit 033cab8

File tree

6 files changed

+32
-8
lines changed

6 files changed

+32
-8
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ RUN cd web && npm install && npm run build
99
RUN python3 -m pip install -U -r ./requirements.txt
1010
# Run
1111
CMD ["pluto", "run"]
12-
EXPOSE 9443
12+
EXPOSE 8080
13+
EXPOSE 8000
14+
EXPOSE 8001

app/main.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
import json
22
import re
33
import tempfile
4-
from pluto_client import Website, Router, HttpRequest, HttpResponse
4+
from pluto_client import (
5+
Website,
6+
WebsiteOptions,
7+
Router,
8+
RouterOptions,
9+
HttpRequest,
10+
HttpResponse,
11+
)
512
import kcl_lib.api as kcl_api
613

714
color_pattern = re.compile(r"\x1b\[[0-9;]+m")
815
api = kcl_api.API()
9-
router = Router("router")
10-
website = Website("./web/dist", "kcl-playground")
16+
router = Router("router", RouterOptions(sim_host="0.0.0.0", sim_port="8000"))
17+
website = Website(
18+
"./web/dist", "kcl-playground", WebsiteOptions(sim_host="0.0.0.0", sim_port="8001")
19+
)
1120
website.addEnv("BACKEND_URL", router.url())
1221

1322

app/main_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import requests
2+
from main import website, router
3+
4+
5+
def test_website():
6+
assert "8000" in website.url()
7+
8+
9+
def test_router():
10+
assert "8001" in router.url()

pluto.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
configs: {}
21
current: aws
32
language: python
43
stacks:
54
- configs: {}
65
name: aws
76
platformType: AWS
87
provisionType: Pulumi
8+
9+
configs:
10+
simulator:
11+
address: "0.0.0.0:8080"

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pluto_client
22
kcl_lib==0.10.0b2
3+
requests

scripts/test.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ PROJECT_NAME=$(grep '"name":' package.json | awk -F '"' '{print $4}')
2121
echo "Project name: $PROJECT_NAME"
2222

2323
# Set environment variables
24-
PORT=$(lsof -Pan -p $PID1 -i | grep LISTEN | awk '{print $9}' | sed 's/.*://')
24+
PORT=8080
2525
export PLUTO_PROJECT_NAME=$PROJECT_NAME
2626
export PLUTO_STACK_NAME=local_run
2727
export PLUTO_PLATFORM_TYPE=Simulator
@@ -49,8 +49,7 @@ python3 -m pytest -s -q --no-header app
4949

5050
# Execute tests within the app/main.py file
5151
print_separator "Executing tests within the app/main.py file"
52-
# TODO: pluto Website resource mock bugfix
53-
# python3 -m pytest -s -q --no-header app/main.py
52+
python3 -m pytest -s -q --no-header app/main.py
5453

5554
# Cleanup
5655
kill $PID1

0 commit comments

Comments
 (0)