Skip to content

Commit 71f678c

Browse files
committed
ci(factory-reset): Fix CI
1 parent 07d6104 commit 71f678c

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

.github/workflows/test.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ jobs:
147147
- name: Install SQLite3
148148
run: sudo apt-get update && sudo apt-get install -y sqlite3
149149

150+
- name: Install xh
151+
run: |
152+
curl -fsSL https://apt.cli.rs/pubkey.asc | sudo tee -a /usr/share/keyrings/rust-tools.asc
153+
curl -fsSL https://apt.cli.rs/rust-tools.list | sudo tee /etc/apt/sources.list.d/rust-tools.list
154+
sudo apt-get update
155+
sudo apt-get install -y xh
156+
150157
# Install our fork of Step CI (has more features we need).
151158
# - name: Install Step CI
152159
# run: npm install -g stepci

tests/integration/test-factory-reset

+18-8
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,35 @@ INTEGRATION_TESTS_DIR="${REPOSITORY_ROOT:?}"/tests/integration
1212
LOCAL_RUN_DIR="${REPOSITORY_ROOT:?}"/local-run
1313
LOCAL_RUN_SCRIPTS="${LOCAL_RUN_DIR:?}"/scripts
1414
BASE_SCENARIO_NAME=demo
15+
: ${INTEGRATION_TEST_HOST:=http://127.0.0.1:8080}
1516

1617
SCENARIO_NAME="${BASE_SCENARIO_NAME:?}-$(date +%s)"
1718
# Compute dynamic variables.
1819
source "${LOCAL_RUN_SCRIPTS:?}"/scenario-files.sh
1920

21+
abort() {
22+
# Do not stop the API after a failure to allow investigation.
23+
# NOTE: In the CI, it will be stopped anyway so it’s perfect.
24+
task integration-test:logs
25+
die "$@"
26+
}
27+
2028
info 'Starting the demo API (already populated with data)…'
2129
edo task local:run -- --detach --api=local --scenario="${BASE_SCENARIO_NAME:?}" --ephemeral --ephemeral-name="${SCENARIO_NAME:?}" --no-update
2230

31+
# Wait a bit to make sure the API is ready (e.g. has run migrations).
32+
sleep 1
33+
2334
info Logging an admin in…
24-
TOKEN="$(edo curl -s -X POST http://localhost:8080/v1/login -u '[email protected]:demo' \| jq -r '.token')"
35+
TOKEN="$(xh POST -I "${INTEGRATION_TEST_HOST:?}"/v1/login -a '[email protected]:demo' content-type: | jq -r '.token')"
36+
[ -n "${TOKEN-}" ] && [ "${TOKEN:?}" != null ] || abort
2537

2638
info Getting the factory reset token…
27-
CONFIRMATION="$(edo curl -s -X DELETE http://localhost:8080 -H "Authorization: Bearer ${TOKEN:?}" \| jq -r '.confirmation')"
39+
CONFIRMATION="$(xh DELETE -I "${INTEGRATION_TEST_HOST:?}" -A bearer -a "${TOKEN:?}" | jq -r '.confirmation')"
40+
[ -n "${CONFIRMATION-}" ] && [ "${CONFIRMATION:?}" != null ] || abort
2841

2942
info Performing the factory reset…
30-
edo curl -s -X DELETE http://localhost:8080 \
31-
-H "Authorization: Bearer ${TOKEN:?}" \
32-
-H "Content-Type: application/json" \
33-
-d '{"confirmation": "'"${CONFIRMATION:?}"'"}'
43+
edo xh DELETE -Iq "${INTEGRATION_TEST_HOST:?}" -A bearer -a "${TOKEN:?}" confirmation="${CONFIRMATION:?}" || abort
3444

3545
info Checking if factory reset deleted everything…
3646

@@ -82,11 +92,11 @@ fi
8292
success API config file reset
8393

8494
info Waiting for the API to restart…
85-
edo curl http://localhost:8080/api-docs/openapi.json --retry 3 --fail -s --output /dev/null || die API stuck restarting.
95+
edo log_as_trace_ xh GET -Iq "${INTEGRATION_TEST_HOST:?}"/api-docs/openapi.json --timeout 3 -p=HBhm || abort API stuck restarting.
8696

8797
info Checking if the API still works…
8898
# Run the `init` integration test, which will initialize the Pod
89-
# (saving us a bunch of `curl` commands).
99+
# (saving us a bunch of `curl`/`xh` commands).
90100
( export SKIP_POD_START=1 SKIP_POD_STOP=1; edo log_as_trace_ task integration-test -- init )
91101
success The API still works!
92102

0 commit comments

Comments
 (0)