Skip to content

Commit 193b129

Browse files
committed
Add a standalone per-platform server test step in CI
1 parent d152edf commit 193b129

File tree

3 files changed

+125
-1
lines changed

3 files changed

+125
-1
lines changed

.github/workflows/ci.yml

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,57 @@ jobs:
5555
name: distributables
5656
path: build/dist/*
5757
if-no-files-found: error
58+
59+
- uses: actions/upload-artifact@v2
60+
with:
61+
name: test-scripts
62+
path: test/distributables-test
63+
if-no-files-found: error
64+
65+
test-distributables:
66+
needs: build
67+
strategy:
68+
matrix:
69+
include:
70+
- platform: Linux
71+
os: "ubuntu-20.04"
72+
test-script: "./unix.sh linux"
73+
- platform: Mac 10.15
74+
os: "macos-10.15"
75+
test-script: "./unix.sh darwin"
76+
- platform: Windows
77+
os: "windows-2019"
78+
test-script: ".\\windows.bat"
79+
fail-fast: false
80+
name: Test on ${{ matrix.platform }}
81+
runs-on: ${{ matrix.os }}
82+
steps:
83+
- name: Get our distributables
84+
uses: actions/download-artifact@v2
85+
with:
86+
name: distributables
87+
path: distributables
88+
89+
- name: Get the test scripts
90+
uses: actions/download-artifact@v2
91+
with:
92+
name: test-scripts
93+
path: .
94+
95+
- name: Make the test script executable
96+
if: matrix.platform != 'Windows'
97+
run: chmod +x unix.sh
98+
99+
- name: Test the server build
100+
run: ${{ matrix.test-script }}
101+
58102
publish:
59103
name: Publish a release
60104
runs-on: "ubuntu-18.04"
61105
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
62-
needs: build
106+
needs:
107+
- build
108+
- test-distributables
63109
steps:
64110
- name: Get our distributables
65111
uses: actions/download-artifact@v2

test/distributables-test/unix.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
ls -la *
6+
7+
tar -xvzf ./distributables/v*/httptoolkit-server-*-$1-x64.tar.gz
8+
9+
./httptoolkit-server/bin/httptoolkit-server start &
10+
SERVER_PID=$!
11+
12+
sleep 5
13+
14+
# CSRF protection fully blocks unrecognized/missing origin requests:
15+
WITH_ORIGIN="-HOrigin: https://app.httptoolkit.tech"
16+
AS_JSON="-HContent-Type: application/json"
17+
18+
# Can start a Mockttp server:
19+
curl "$WITH_ORIGIN" "$AS_JSON" -v --fail 'http://127.0.0.1:45456/start?port=\{"startPort":8000,"endPort":65535\}' -d '{}'
20+
21+
# Can query the API server version:
22+
curl "$WITH_ORIGIN" "$AS_JSON" -v --fail http://127.0.0.1:45457/ -d '{"query": "query getVersion { version }"}'
23+
24+
# Can get config
25+
curl "$WITH_ORIGIN" "$AS_JSON" -v --fail http://127.0.0.1:45457/ -d '{"query": "query getConfig { config { certificateContent certificatePath certificateFingerprint } }"}'
26+
27+
# Can query interceptors
28+
curl "$WITH_ORIGIN" "$AS_JSON" -v --fail http://127.0.0.1:45457/ -d '{"query": "query getInterceptors { interceptors { id version, metadata isActivable isActive(proxyPort: 8000) } }"}'
29+
30+
# ^ This will fail if they receive anything but a 200 result.
31+
# This ensures that the server is startable, and has minimal functionality for launch.

test/distributables-test/windows.bat

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
@echo off
2+
3+
REM Extract the tarball. Tar doesn't support wildcards on windows, DIR only supports one wildcard, so we have to do this mess:
4+
cd distributables\v*\
5+
set GET_TAR="dir /b httptoolkit-server-*-win32-x64.tar.gz"
6+
FOR /F "tokens=*" %%i IN (' %GET_TAR% ') DO SET TAR_PATH=%%i
7+
8+
tar -xvzf %TAR_PATH%
9+
10+
START "server" .\httptoolkit-server\bin\httptoolkit-server start
11+
12+
REM The closest we can get to a 10 second delay on Windows in CI, ick:
13+
ping -n 10 127.0.0.1 >NUL
14+
15+
REM CSRF protection fully blocks unrecognized/missing origin requests:
16+
set WITH_ORIGIN="-HOrigin: https://app.httptoolkit.tech"
17+
set AS_JSON="-HContent-Type: application/json"
18+
19+
REM Can start a Mockttp server:
20+
curl %WITH_ORIGIN% %AS_JSON% -v --fail -X POST "http://127.0.0.1:45456/start?port=\{\"startPort\":8000,\"endPort\":65535\}" || goto :error
21+
22+
REM Can query the API server version:
23+
curl %WITH_ORIGIN% %AS_JSON% -v --fail http://127.0.0.1:45457/ -d "{\"query\": \"query getVersion { version }\"}" || goto :error
24+
25+
REM Can get config
26+
curl %WITH_ORIGIN% %AS_JSON% -v --fail http://127.0.0.1:45457/ -d "{\"query\": \"query getConfig { config { certificateContent certificatePath certificateFingerprint } }\"}" || goto :error
27+
28+
REM Can query interceptors
29+
curl %WITH_ORIGIN% %AS_JSON% -v --fail http://127.0.0.1:45457/ -d "{\"query\": \"query getInterceptors { interceptors { id version, metadata isActivable isActive(proxyPort: 8000) } }\"}" || goto :error
30+
31+
REM ^ This will fail if they receive anything but a 200 result.
32+
REM This ensures that the server is startable, and has minimal functionality for launch.
33+
34+
goto :success
35+
36+
:error
37+
set err=%errorlevel%
38+
39+
taskkill /FI "WindowTitle eq server*" /T /F
40+
echo Test failed with error #%err%.
41+
exit /b %err%
42+
43+
:success
44+
echo All good.
45+
46+
REM Shut down by matching title passed to START to run in the background
47+
taskkill /FI "WindowTitle eq server*" /T /F

0 commit comments

Comments
 (0)