Skip to content

Commit

Permalink
ci: add unit test for the main app
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Aug 23, 2024
1 parent a7d1159 commit af08152
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ RUN cd web && npm install && npm run build
RUN python3 -m pip install -U -r ./requirements.txt
# Run
CMD ["pluto", "run"]
EXPOSE 9443
EXPOSE 8080
EXPOSE 8000
EXPOSE 8001
15 changes: 12 additions & 3 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import json
import re
import tempfile
from pluto_client import Website, Router, HttpRequest, HttpResponse
from pluto_client import (
Website,
WebsiteOptions,
Router,
RouterOptions,
HttpRequest,
HttpResponse,
)
import kcl_lib.api as kcl_api

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


Expand Down
13 changes: 13 additions & 0 deletions app/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import requests
from main import website, router


def test_website():
print(website.url())


def test_router():
print(router.url())
response = requests.get(router.url() + "/hello?name=pluto")
if response.status_code == 200:
print(response.text)
5 changes: 4 additions & 1 deletion pluto.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
configs: {}
current: aws
language: python
stacks:
- configs: {}
name: aws
platformType: AWS
provisionType: Pulumi

configs:
simulator:
address: "0.0.0.0:8080"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pluto_client
kcl_lib==0.10.0b2
requests
5 changes: 2 additions & 3 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ PROJECT_NAME=$(grep '"name":' package.json | awk -F '"' '{print $4}')
echo "Project name: $PROJECT_NAME"

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

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

# Cleanup
kill $PID1
Expand Down

0 comments on commit af08152

Please sign in to comment.