piilloparametrit eksplisiittisiksi
This commit is contained in:
@@ -26,19 +26,8 @@ function bashQuiet(cmd) {
|
||||
});
|
||||
}
|
||||
|
||||
function envBlock() {
|
||||
return [
|
||||
'export GITEA_API_URL="http://localhost:18080"',
|
||||
'export GITEA_TOKEN="test-token-abc123"',
|
||||
'export GITHUB_REPOSITORY="test-owner/test-repo"',
|
||||
'export GITHUB_SHA="abc123def456789012345678901234567890abcd"',
|
||||
'export GITHUB_SERVER_URL="https://gitea.example.com"',
|
||||
'export GITHUB_RUN_ID="42"',
|
||||
].join('; ');
|
||||
}
|
||||
|
||||
function runReportStatus(args) {
|
||||
return bash(`${envBlock()}; bash "${REPORT_SCRIPT}" ${args}`);
|
||||
return bash(`export GITHUB_REPOSITORY="test-owner/test-repo" GITHUB_SHA="abc123def456789012345678901234567890abcd" GITHUB_RUN_ID="42"; bash "${REPORT_SCRIPT}" ${args}`);
|
||||
}
|
||||
|
||||
function getMockBody() {
|
||||
@@ -50,7 +39,7 @@ function getMockPath() {
|
||||
}
|
||||
|
||||
When('a build step starts executing', function () {
|
||||
const r = runReportStatus('pending "Building project" "http://example.com/build/42"');
|
||||
const r = runReportStatus('pending "Building project" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"');
|
||||
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}: ${r.stderr}`);
|
||||
});
|
||||
|
||||
@@ -61,7 +50,7 @@ Then('the commit shows a pending status with a description of the step', functio
|
||||
});
|
||||
|
||||
When('a build step completes successfully and reports its results', function () {
|
||||
const r = runReportStatus('success "Unit tests OK" "http://example.com/reports/cucumber.html" "unit-test"');
|
||||
const r = runReportStatus('success "Unit tests OK" "http://example.com/reports/cucumber.html" "http://localhost:18080" "test-token-abc123" "unit-test"');
|
||||
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`);
|
||||
});
|
||||
|
||||
@@ -72,7 +61,7 @@ Then('the commit shows a success status with a clickable link to the results', f
|
||||
});
|
||||
|
||||
When('a build step fails', function () {
|
||||
const r = runReportStatus('failure "Tests failed: 3 of 10" "http://example.com/build/42"');
|
||||
const r = runReportStatus('failure "Tests failed: 3 of 10" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"');
|
||||
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`);
|
||||
});
|
||||
|
||||
@@ -83,11 +72,11 @@ Then('the commit shows a failure status with a description of what went wrong',
|
||||
});
|
||||
|
||||
When('several build steps each report their own status to the same commit', function () {
|
||||
runReportStatus('pending "Build started" "http://example.com/build/42" "ci-build"');
|
||||
runReportStatus('pending "Build started" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123" "ci-build"');
|
||||
execSync('sleep 0.3', { stdio: 'ignore' });
|
||||
runReportStatus('success "Unit tests passed" "http://example.com/reports/unit.html" "unit-test"');
|
||||
runReportStatus('success "Unit tests passed" "http://example.com/reports/unit.html" "http://localhost:18080" "test-token-abc123" "unit-test"');
|
||||
execSync('sleep 0.3', { stdio: 'ignore' });
|
||||
runReportStatus('success "Integration tests passed" "http://example.com/reports/integration.html" "integration-test"');
|
||||
runReportStatus('success "Integration tests passed" "http://example.com/reports/integration.html" "http://localhost:18080" "test-token-abc123" "integration-test"');
|
||||
});
|
||||
|
||||
Then('each status appears under a unique label on the commit', function () {
|
||||
@@ -104,7 +93,7 @@ Then('each status appears under a unique label on the commit', function () {
|
||||
});
|
||||
|
||||
When('a deployment finishes for a commit that originated from another repository', function () {
|
||||
const r = runReportStatus('success "Deployed to staging" "http://example.com/deploy/42" "deploy-staging" "rootabc123" "services/temperature-store"');
|
||||
const r = runReportStatus('success "Deployed to staging" "http://example.com/deploy/42" "http://localhost:18080" "test-token-abc123" "deploy-staging" "" "" "rootabc123" "services/temperature-store"');
|
||||
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`);
|
||||
});
|
||||
|
||||
@@ -122,7 +111,7 @@ When('a build step tries to report status but the build system is unavailable',
|
||||
bashQuiet(`source "${MOCK_SCRIPT}" && mock_stop`);
|
||||
execSync('sleep 0.3', { stdio: 'ignore' });
|
||||
bashQuiet(`source "${MOCK_SCRIPT}" && mock_set_response 500 && mock_start`);
|
||||
const r = runReportStatus('success "Should fail" "http://example.com"');
|
||||
const r = runReportStatus('success "Should fail" "http://example.com" "http://localhost:18080" "test-token-abc123"');
|
||||
this.reportStatusFailed = (r.status !== 0);
|
||||
});
|
||||
|
||||
|
||||
+21
-22
@@ -2,8 +2,6 @@
|
||||
|
||||
setup() {
|
||||
source tests/helpers/mock-api.sh
|
||||
export GITEA_API_URL="http://localhost:18080"
|
||||
export GITEA_TOKEN="test-token-abc123"
|
||||
export GITHUB_REPOSITORY="test-owner/test-repo"
|
||||
export GITHUB_SHA="abc123def456789012345678901234567890abcd"
|
||||
export GITHUB_SERVER_URL="https://gitea.example.com"
|
||||
@@ -16,7 +14,7 @@ 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" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"
|
||||
[ "$status" -eq 0 ]
|
||||
path=$(mock_get_request_path)
|
||||
[[ "$path" == "/api/v1/repos/test-owner/test-repo/statuses/abc123def456789012345678901234567890abcd" ]]
|
||||
@@ -30,7 +28,7 @@ teardown() {
|
||||
|
||||
@test "success status with url and custom key" {
|
||||
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" "http://example.com/reports/cucumber.html" "http://localhost:18080" "test-token-abc123" "unit-test"
|
||||
[ "$status" -eq 0 ]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"success"'* ]]
|
||||
@@ -41,7 +39,7 @@ teardown() {
|
||||
|
||||
@test "failure status is POSTed correctly" {
|
||||
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" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"
|
||||
[ "$status" -eq 0 ]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"failure"'* ]]
|
||||
@@ -50,7 +48,7 @@ teardown() {
|
||||
|
||||
@test "error status is POSTed correctly" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh error "Build timed out" "http://example.com/build/42"
|
||||
run bash scripts/report-status.sh error "Build timed out" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"
|
||||
[ "$status" -eq 0 ]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"state":"error"'* ]]
|
||||
@@ -58,7 +56,7 @@ teardown() {
|
||||
|
||||
@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"
|
||||
run bash scripts/report-status.sh success "Deployed to staging" "http://example.com/deploy/42" "http://localhost:18080" "test-token-abc123" "deploy-staging" "" "" "rootabc123" "services/temperature-store"
|
||||
[ "$status" -eq 0 ]
|
||||
path=$(mock_get_request_path)
|
||||
[[ "$path" == "/api/v1/repos/services/temperature-store/statuses/rootabc123" ]]
|
||||
@@ -69,7 +67,7 @@ teardown() {
|
||||
|
||||
@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"
|
||||
run bash scripts/report-status.sh success "Partial cross-repo" "http://example.com" "http://localhost:18080" "test-token-abc123" "my-key" "" "" "abc"
|
||||
[ "$status" -eq 0 ]
|
||||
path=$(mock_get_request_path)
|
||||
[[ "$path" == "/api/v1/repos/test-owner/test-repo/statuses/abc123def456789012345678901234567890abcd" ]]
|
||||
@@ -77,7 +75,7 @@ teardown() {
|
||||
|
||||
@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" "http://example.com/build/42" "http://localhost:18080" "test-token-abc123"
|
||||
[ "$status" -eq 0 ]
|
||||
body=$(mock_get_request_body)
|
||||
[[ "$body" == *'"context":"commit-abc123de"'* ]]
|
||||
@@ -86,38 +84,39 @@ 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" "http://example.com" "http://localhost:18080" "test-token-abc123"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@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"
|
||||
@test "missing gitea_api_url argument causes exit 1 with error message" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh pending "Test" "http://example.com" "" "test-token-abc123"
|
||||
[ "$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"
|
||||
@test "missing gitea_token argument causes exit 1 with error message" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh pending "Test" "http://example.com" "http://localhost:18080" ""
|
||||
[ "$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" "http://example.com" "http://localhost:18080" "test-token-abc123"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "missing required description argument causes exit 1" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh pending "" "http://example.com"
|
||||
run bash scripts/report-status.sh pending "" "http://example.com" "http://localhost:18080" "test-token-abc123"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "missing required url argument causes exit 1" {
|
||||
@test "missing required state argument is checked before gitea_api_url" {
|
||||
mock_start
|
||||
run bash scripts/report-status.sh pending "desc" ""
|
||||
run bash scripts/report-status.sh "" "desc" "http://example.com" "" ""
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"state"* ]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user