fix fragile tests
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 19s
acc-tests Cucumber test report
CI Feature / Cucumber tests (push) Failing after 2m11s
unit-tests Bats test report
CI Feature / Bats tests (push) Failing after 7m10s
CI Feature / Report Summary (push) Successful in 5s

This commit is contained in:
moilanik
2026-06-20 13:34:03 +03:00
parent 0a9a9c88f1
commit a039e6637e
5 changed files with 35 additions and 15 deletions
-1
View File
@@ -5,7 +5,6 @@ source "$BATS_TEST_DIRNAME/helpers/mock-api.sh"
setup() { setup() {
export GITEA_TOKEN=test-token export GITEA_TOKEN=test-token
export GIT_TAG_PREFIX="" export GIT_TAG_PREFIX=""
export SERVER_URL="http://localhost:18080"
export REPO="niko/test" export REPO="niko/test"
export SHA="abc123" export SHA="abc123"
rm -rf /tmp/build-ctx rm -rf /tmp/build-ctx
+7 -7
View File
@@ -19,7 +19,7 @@ teardown() {
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}} {"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
]' ]'
mock_start mock_start
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123" run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
} }
@@ -31,7 +31,7 @@ teardown() {
{"code":200,"body":{"id":1,"status":"completed","conclusion":"failure"}} {"code":200,"body":{"id":1,"status":"completed","conclusion":"failure"}}
]' ]'
mock_start mock_start
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123" run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@@ -43,7 +43,7 @@ teardown() {
{"code":200,"body":{"id":1,"status":"completed","conclusion":"cancelled"}} {"code":200,"body":{"id":1,"status":"completed","conclusion":"cancelled"}}
]' ]'
mock_start mock_start
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123" run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@@ -61,7 +61,7 @@ teardown() {
{"code":200,"body":{"id":1,"status":"running"}} {"code":200,"body":{"id":1,"status":"running"}}
]' ]'
mock_start mock_start
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123" "0.001" run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123" "0.001"
[ "$status" -eq 124 ] [ "$status" -eq 124 ]
} }
@@ -70,7 +70,7 @@ teardown() {
{"code":500} {"code":500}
]' ]'
mock_start mock_start
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123" run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
} }
@@ -81,7 +81,7 @@ teardown() {
{"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}} {"code":200,"body":{"id":1,"status":"completed","conclusion":"success"}}
]' ]'
mock_start mock_start
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "http://localhost:18080" "test-token-abc123" run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{"version":"1.2.3"}' "$GITEA_API_URL" "test-token-abc123"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
path=$(mock_get_first_request_path) path=$(mock_get_first_request_path)
[[ "$path" == *"/api/v1/repos/test-owner/test-repo/actions/workflows/test.yml/dispatches"* ]] [[ "$path" == *"/api/v1/repos/test-owner/test-repo/actions/workflows/test.yml/dispatches"* ]]
@@ -126,7 +126,7 @@ teardown() {
{"code":200,"body":{"workflow_runs":[]}} {"code":200,"body":{"workflow_runs":[]}}
]' ]'
mock_start mock_start
run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{}' "http://localhost:18080" "test-token-abc123" run bash scripts/dispatch-workflow.sh "test-owner/test-repo" "test.yml" "main" '{}' "$GITEA_API_URL" "test-token-abc123"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[[ "$output" == *"ERROR"* ]] [[ "$output" == *"ERROR"* ]]
} }
+19 -3
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
MOCK_PORT=18080 MOCK_PORT=""
MOCK_PID="" MOCK_PID=""
MOCK_REQUEST_FILE="" MOCK_REQUEST_FILE=""
MOCK_RESPONSE_CODE=201 MOCK_RESPONSE_CODE=201
@@ -9,11 +9,17 @@ MOCK_STATE_FILE="/tmp/mock_api_state"
MOCK_SEQUENCE_FILE="" MOCK_SEQUENCE_FILE=""
MOCK_CONFIG_FILE="" MOCK_CONFIG_FILE=""
_free_port() {
python3 -c "import socket; s=socket.socket(); s.bind(('',0)); print(s.getsockname()[1]); s.close()"
}
_kill_port() { _kill_port() {
local pids local pids
pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true
[ -n "$pids" ] && kill -9 $pids 2>/dev/null || true [ -n "$pids" ] && kill $pids 2>/dev/null || true
sleep 0.5 sleep 0.5
pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true
[ -n "$pids" ] && kill -9 $pids 2>/dev/null || true
} }
_wait_port_free() { _wait_port_free() {
@@ -26,10 +32,14 @@ _wait_port_free() {
_wait_port_ready() { _wait_port_ready() {
local i=0 local i=0
while ! lsof -ti ":$MOCK_PORT" >/dev/null 2>&1 && [ $i -lt 5 ]; do while [ $i -lt 50 ]; do
if nc -z localhost "$MOCK_PORT" 2>/dev/null; then
return 0
fi
sleep 0.2 sleep 0.2
i=$((i + 1)) i=$((i + 1))
done done
return 1
} }
mock_set_sequence() { mock_set_sequence() {
@@ -43,6 +53,12 @@ mock_clear_sequence() {
} }
mock_start() { mock_start() {
MOCK_PORT=$(_free_port)
export MOCK_PORT
MOCK_URL="http://localhost:${MOCK_PORT}"
export SERVER_URL="$MOCK_URL"
export GITEA_API_URL="$MOCK_URL"
MOCK_RESPONSE_CODE="${MOCK_RESPONSE_CODE:-201}" MOCK_RESPONSE_CODE="${MOCK_RESPONSE_CODE:-201}"
MOCK_REQUEST_FILE=$(mktemp) MOCK_REQUEST_FILE=$(mktemp)
echo "$MOCK_REQUEST_FILE" > "$MOCK_STATE_FILE" echo "$MOCK_REQUEST_FILE" > "$MOCK_STATE_FILE"
+5 -2
View File
@@ -63,9 +63,10 @@ teardown() {
{"code":200,"body":"published"} {"code":200,"body":"published"}
]' ]'
mock_start mock_start
export GIT_PAGES_URL="http://localhost:${MOCK_PORT}"
run bash scripts/publish-git-pages.sh "unit-tests" run bash scripts/publish-git-pages.sh "unit-tests"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "$output" == "http://localhost:18080/test-owner/test-repo/reports/abc123de" ]] [[ "$output" == "${GIT_PAGES_URL}/test-owner/test-repo/reports/abc123de" ]]
} }
@test "publish with suite subpath" { @test "publish with suite subpath" {
@@ -75,9 +76,10 @@ teardown() {
{"code":200,"body":"published"} {"code":200,"body":"published"}
]' ]'
mock_start mock_start
export GIT_PAGES_URL="http://localhost:${MOCK_PORT}"
run bash scripts/publish-git-pages.sh "sub/suite" run bash scripts/publish-git-pages.sh "sub/suite"
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
[[ "$output" == "http://localhost:18080/test-owner/test-repo/reports/abc123de" ]] [[ "$output" == "${GIT_PAGES_URL}/test-owner/test-repo/reports/abc123de" ]]
} }
@test "git-pages returns HTTP 500 → exit 1" { @test "git-pages returns HTTP 500 → exit 1" {
@@ -85,6 +87,7 @@ teardown() {
{"code":500,"body":"internal error"} {"code":500,"body":"internal error"}
]' ]'
mock_start mock_start
export GIT_PAGES_URL="http://localhost:${MOCK_PORT}"
run bash scripts/publish-git-pages.sh "unit-tests" run bash scripts/publish-git-pages.sh "unit-tests"
[ "$status" -eq 1 ] [ "$status" -eq 1 ]
[[ "$output" == *"500"* ]] [[ "$output" == *"500"* ]]
+4 -2
View File
@@ -23,7 +23,8 @@ teardown() {
body=$(mock_get_request_body) body=$(mock_get_request_body)
[[ "$body" == *'"state":"pending"'* ]] [[ "$body" == *'"state":"pending"'* ]]
[[ "$body" == *'"description":"Building project"'* ]] [[ "$body" == *'"description":"Building project"'* ]]
[[ "$body" == *'"target_url":"http://localhost:18080/test-owner/test-repo/actions/runs/42"'* ]] expected_url="${GITEA_API_URL}/test-owner/test-repo/actions/runs/42"
[[ "$body" == *"\"target_url\":\"${expected_url}\""* ]]
method=$(mock_get_request_method) method=$(mock_get_request_method)
[[ "$method" == "POST" ]] [[ "$method" == "POST" ]]
} }
@@ -44,7 +45,8 @@ teardown() {
[ "$status" -eq 0 ] [ "$status" -eq 0 ]
body=$(mock_get_request_body) body=$(mock_get_request_body)
[[ "$body" == *'"state":"failure"'* ]] [[ "$body" == *'"state":"failure"'* ]]
[[ "$body" == *'"target_url":"http://localhost:18080/test-owner/test-repo/actions/runs/42"'* ]] expected_url="${GITEA_API_URL}/test-owner/test-repo/actions/runs/42"
[[ "$body" == *"\"target_url\":\"${expected_url}\""* ]]
} }
@test "default key when not provided" { @test "default key when not provided" {