pipeline siivous ja testikattavuuden nosto (#9)
Co-authored-by: moilanik <niko.moilanen@tietoevry.com> Reviewed-on: #9
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 GITEA_API_URL="http://localhost:18080" GITEA_TOKEN="test-token-abc123" GIT_PAGES_URL="https://reports.example.com" 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"');
|
||||
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}: ${r.stderr}`);
|
||||
});
|
||||
|
||||
@@ -61,18 +50,18 @@ 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" unit-test cucumber/');
|
||||
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`);
|
||||
});
|
||||
|
||||
Then('the commit shows a success status with a clickable link to the results', function () {
|
||||
const body = getMockBody();
|
||||
if (!body.includes('"state":"success"')) throw new Error('Expected success status');
|
||||
if (!body.includes('"target_url":"http://example.com/reports/cucumber.html"')) throw new Error('Expected URL');
|
||||
if (!body.includes('"target_url":"https://reports.example.com/test-owner/test-repo/reports/abc123de/cucumber/"')) throw new Error('Expected URL');
|
||||
});
|
||||
|
||||
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"');
|
||||
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" 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" 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" 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" deploy-staging');
|
||||
if (r.status !== 0) throw new Error(`Expected exit 0, got ${r.status}`);
|
||||
});
|
||||
|
||||
@@ -114,15 +103,15 @@ Then('the source commit shows the deployment status alongside the build status',
|
||||
if (!body.includes('"context":"deploy-staging"')) throw new Error('Expected deploy-staging context');
|
||||
|
||||
const pathStr = getMockPath();
|
||||
if (!pathStr.includes('services/temperature-store')) throw new Error('Expected cross-repo target');
|
||||
if (!pathStr.includes('rootabc123')) throw new Error('Expected root commit');
|
||||
if (!pathStr.includes('test-owner/test-repo')) throw new Error('Expected default repo target');
|
||||
if (!pathStr.includes('abc123def456789012345678901234567890abcd')) throw new Error('Expected default commit');
|
||||
});
|
||||
|
||||
When('a build step tries to report status but the build system is unavailable', function () {
|
||||
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"');
|
||||
this.reportStatusFailed = (r.status !== 0);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user