pipeline siivous ja testikattavuuden nosto (#9)
Co-authored-by: moilanik <niko.moilanen@tietoevry.com> Reviewed-on: #9
This commit is contained in:
+31
-51
@@ -4,9 +4,9 @@ setup() {
|
||||
source tests/helpers/mock-api.sh
|
||||
export GITEA_API_URL="http://localhost:18080"
|
||||
export GITEA_TOKEN="test-token-abc123"
|
||||
export GIT_PAGES_URL="https://reports.example.com"
|
||||
export GITHUB_REPOSITORY="test-owner/test-repo"
|
||||
export GITHUB_SHA="abc123def456789012345678901234567890abcd"
|
||||
export GITHUB_SERVER_URL="https://gitea.example.com"
|
||||
export GITHUB_RUN_ID="42"
|
||||
}
|
||||
|
||||
@@ -16,68 +16,40 @@ teardown() {
|
||||
|
||||
@test "pending status is POSTed with correct payload" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh pending "Building project" "http://example.com/build/42"
|
||||
run bash scripts/report-status.sh pending "Building project"
|
||||
[ "$status" -eq 0 ]
|
||||
path=$(mock_get_request_path)
|
||||
[[ "$path" == "/api/v1/repos/test-owner/test-repo/statuses/abc123def456789012345678901234567890abcd" ]]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"pending"'* ]]
|
||||
[[ "$body" == *'"description":"Building project"'* ]]
|
||||
[[ "$body" == *'"target_url":"http://example.com/build/42"'* ]]
|
||||
[[ "$body" == *'"target_url":"http://localhost:18080/test-owner/test-repo/actions/runs/42"'* ]]
|
||||
method=$(mock_get_request_method)
|
||||
[[ "$method" == "POST" ]]
|
||||
}
|
||||
|
||||
@test "success status with url and custom key" {
|
||||
@test "success status with custom key and suite builds report URL" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh success "Unit tests OK" "http://example.com/reports/cucumber.html" "unit-test"
|
||||
run bash scripts/report-status.sh success "Unit tests OK" unit-test cucumber
|
||||
[ "$status" -eq 0 ]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"success"'* ]]
|
||||
[[ "$body" == *'"description":"Unit tests OK"'* ]]
|
||||
[[ "$body" == *'"target_url":"http://example.com/reports/cucumber.html"'* ]]
|
||||
[[ "$body" == *'"context":"unit-test"'* ]]
|
||||
[[ "$body" == *'"target_url":"https://reports.example.com/test-owner/test-repo/reports/abc123de/cucumber/"'* ]]
|
||||
}
|
||||
|
||||
@test "failure status is POSTed correctly" {
|
||||
@test "failure status constructs run URL when no suite" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh failure "Tests failed: 3 of 10" "http://example.com/build/42"
|
||||
run bash scripts/report-status.sh failure "Tests failed: 3 of 10"
|
||||
[ "$status" -eq 0 ]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"failure"'* ]]
|
||||
[[ "$body" == *'"description":"Tests failed: 3 of 10"'* ]]
|
||||
}
|
||||
|
||||
@test "error status is POSTed correctly" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh error "Build timed out" "http://example.com/build/42"
|
||||
[ "$status" -eq 0 ]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"error"'* ]]
|
||||
}
|
||||
|
||||
@test "cross-repo: root_commit and root_repo override target" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh success "Deployed to staging" "http://example.com/deploy/42" "deploy-staging" "rootabc123" "services/temperature-store"
|
||||
[ "$status" -eq 0 ]
|
||||
path=$(mock_get_request_path)
|
||||
[[ "$path" == "/api/v1/repos/services/temperature-store/statuses/rootabc123" ]]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"success"'* ]]
|
||||
[[ "$body" == *'"context":"deploy-staging"'* ]]
|
||||
}
|
||||
|
||||
@test "cross-repo: only root_commit without root_repo is ignored" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh success "Partial cross-repo" "http://example.com" "my-key" "abc"
|
||||
[ "$status" -eq 0 ]
|
||||
path=$(mock_get_request_path)
|
||||
[[ "$path" == "/api/v1/repos/test-owner/test-repo/statuses/abc123def456789012345678901234567890abcd" ]]
|
||||
[[ "$body" == *'"target_url":"http://localhost:18080/test-owner/test-repo/actions/runs/42"'* ]]
|
||||
}
|
||||
|
||||
@test "default key when not provided" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh pending "Build started" "http://example.com/build/42"
|
||||
run bash scripts/report-status.sh pending "Build started"
|
||||
[ "$status" -eq 0 ]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"context":"commit-abc123de"'* ]]
|
||||
@@ -86,38 +58,46 @@ teardown() {
|
||||
@test "API returns 500 causes exit 1" {
|
||||
mock_set_response 500
|
||||
mock_start
|
||||
run bash scripts/report-status.sh success "Should fail" "http://example.com"
|
||||
run bash scripts/report-status.sh success "Should fail"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "cross-repo: ROOT_COMMIT and ROOT_REPO override target" {
|
||||
export ROOT_COMMIT="rootabc123"
|
||||
export ROOT_REPO="services/temperature-store"
|
||||
mock_start
|
||||
run bash scripts/report-status.sh success "Deployed to staging" deploy-staging
|
||||
[ "$status" -eq 0 ]
|
||||
path=$(mock_get_request_path)
|
||||
[[ "$path" == "/api/v1/repos/services/temperature-store/statuses/rootabc123" ]]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"success"'* ]]
|
||||
[[ "$body" == *'"context":"deploy-staging"'* ]]
|
||||
unset ROOT_COMMIT ROOT_REPO
|
||||
}
|
||||
|
||||
@test "missing GITEA_API_URL causes exit 1 with error message" {
|
||||
unset GITEA_API_URL
|
||||
run bash scripts/report-status.sh pending "Test" "http://example.com"
|
||||
run bash scripts/report-status.sh pending "Test"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"ERROR"* ]] || [[ "$output" == *"GITEA_API_URL"* ]]
|
||||
[[ "$output" == *"ERROR"* || "$output" == *"GITEA_API_URL"* ]]
|
||||
}
|
||||
|
||||
@test "missing GITEA_TOKEN causes exit 1 with error message" {
|
||||
unset GITEA_TOKEN
|
||||
run bash scripts/report-status.sh pending "Test" "http://example.com"
|
||||
run bash scripts/report-status.sh pending "Test"
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"ERROR"* ]] || [[ "$output" == *"GITEA_TOKEN"* ]]
|
||||
[[ "$output" == *"ERROR"* || "$output" == *"GITEA_TOKEN"* ]]
|
||||
}
|
||||
|
||||
@test "missing required state argument causes exit 1" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh "" "desc" "http://example.com"
|
||||
run bash scripts/report-status.sh "" "desc"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "missing required description argument causes exit 1" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh pending "" "http://example.com"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "missing required url argument causes exit 1" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh pending "desc" ""
|
||||
run bash scripts/report-status.sh pending ""
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user