Skip to content

Commit 4bf055a

Browse files
Jonathas-Conceicaootavio
authored andcommitted
CI: Add tests for examples
API is tested using the OpenAPI doc and APISprout, while listener example is tested using using socat Signed-off-by: Jonathas-Conceicao <[email protected]>
1 parent 09aca6a commit 4bf055a

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,48 @@ jobs:
2222
python-version: ${{ matrix.python }}
2323
- name: Install Dependencies
2424
run: |
25-
pip install tox coveralls
25+
sudo apt-get update; sudo apt-get install socat
26+
pip install tox
2627
- name: Run Tox
2728
run: tox -e py
29+
- name: Run API test
30+
run: |
31+
wget https://raw.githubusercontent.com/UpdateHub/updatehub/master/doc/agent-http.yaml \
32+
-O agent-http.yaml
33+
34+
docker run \
35+
--rm \
36+
--detach=true \
37+
--name agent-sdk-python-mock \
38+
-p 8080:8000 \
39+
-v $PWD/agent-http.yaml:/api.yaml \
40+
danielgtaylor/apisprout@sha256:6c07143937e57095d8478efc8ab7eab52b44e67c7673285f8c0a2bf4a7b137ad \
41+
/api.yaml --validate-request
42+
43+
PYTHONPATH=. python examples/api.py
44+
- name: Run listener test
45+
run: |
46+
export UH_LISTENER_TEST=updatehub-statechange.sock
47+
PYTHONPATH=. python3.6 examples/state_change_listener.py &
48+
49+
while [ ! -S "$UH_LISTENER_TEST" ]; do
50+
sleep 1
51+
done
52+
53+
if [[ "$(echo "entry_point" | socat - UNIX-CONNECT:updatehub-statechange.sock)" != "" ]]; then
54+
echo "Unexpected entry_point response"
55+
exit 1
56+
fi
57+
if [[ "$(echo "downloading" | socat - UNIX-CONNECT:updatehub-statechange.sock)" != "cancel" ]]; then
58+
echo "Unexpected downloading response"
59+
exit 2
60+
fi
61+
if [[ "$(echo "error foo" | socat - UNIX-CONNECT:updatehub-statechange.sock)" != "try_again 10" ]]; then
62+
echo "Unexpected error response"
63+
exit 3
64+
fi
65+
if [[ "$(echo "rebooting" | socat - UNIX-CONNECT:updatehub-statechange.sock)" != "" ]]; then
66+
echo "Unexpected rebooting response"
67+
exit 4
68+
fi
2869

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ updatehub_agent_sdk.egg-info/
99
test-report.xml
1010
*.pyc
1111
coverage.xml
12+
agent-http.yaml

0 commit comments

Comments
 (0)