Skip to content

Commit

Permalink
chore: Add test cases for circle-ci ei-info extn
Browse files Browse the repository at this point in the history
  • Loading branch information
leelaprasadv committed Dec 15, 2024
1 parent 636d9f0 commit 610c1a8
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 28 deletions.
106 changes: 78 additions & 28 deletions test/ext-ci-info.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@ describe('extensions - ci-info', () => {
process.env.GITHUB_RUN_NUMBER = '';
process.env.GITHUB_WORKFLOW = '';

process.env.GITLAB_CI=''
process.env.CI_PROJECT_URL = ''
process.env.CI_PROJECT_NAME = ''
process.env.CI_COMMIT_REF_NAME = ''
process.env.CI_COMMIT_SHA = ''
process.env.CI_JOB_URL = ''
process.env.CI_JOB_ID = ''
process.env.CI_JOB_NAME = ''
process.env.CI_PIPELINE_SOURCE = ''
process.env.GITLAB_CI = '';
process.env.CI_PROJECT_URL = '';
process.env.CI_PROJECT_NAME = '';
process.env.CI_COMMIT_REF_NAME = '';
process.env.CI_COMMIT_SHA = '';
process.env.CI_JOB_URL = '';
process.env.CI_JOB_ID = '';
process.env.CI_JOB_NAME = '';
process.env.CI_PIPELINE_SOURCE = '';
process.env.GITLAB_USER_LOGIN = '';

process.env.CIRCLECI = '';
process.env.CIRCLE_REPOSITORY_URL = '';
process.env.CIRCLE_PROJECT_REPONAME = ''; // Need to find a better match
process.env.CIRCLE_SHA1 = '';
process.env.CIRCLE_BRANCH = '';
process.env.CIRCLE_BUILD_URL = '';
process.env.CIRCLE_BUILD_NUM = '';
process.env.CIRCLE_JOB = '';
process.env.CIRCLE_USERNAME = '';

process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = '';
process.env.BUILD_REPOSITORY_URI = '';
process.env.BUILD_REPOSITORY_NAME = '';
Expand Down Expand Up @@ -182,15 +192,15 @@ describe('extensions - ci-info', () => {
});

it('should send test-summary with gitlab ci information to slack', async () => {
process.env.GITLAB_CI=true
process.env.CI_PROJECT_URL = 'https://gitlab.com/testbeats/demo'
process.env.CI_PROJECT_NAME = 'demo'
process.env.CI_COMMIT_REF_NAME = 'branch'
process.env.CI_COMMIT_SHA = 'sha'
process.env.CI_JOB_URL = 'https://gitlab.com/testbeats/demo/-/jobs/id-123'
process.env.CI_JOB_ID = 'id-123'
process.env.CI_JOB_NAME = 'Test'
process.env.CI_PIPELINE_SOURCE = 'push'
process.env.GITLAB_CI = true;
process.env.CI_PROJECT_URL = 'https://gitlab.com/testbeats/demo';
process.env.CI_PROJECT_NAME = 'demo';
process.env.CI_COMMIT_REF_NAME = 'branch';
process.env.CI_COMMIT_SHA = 'sha';
process.env.CI_JOB_URL = 'https://gitlab.com/testbeats/demo/-/jobs/id-123';
process.env.CI_JOB_ID = 'id-123';
process.env.CI_JOB_NAME = 'Test';
process.env.CI_PIPELINE_SOURCE = 'push';
process.env.GITLAB_USER_LOGIN = 'dummy-user';

const id = mock.addInteraction('post test-summary with gitlab ci-info to slack');
Expand Down Expand Up @@ -223,16 +233,16 @@ describe('extensions - ci-info', () => {
});

it('should send test-summary with gitlab ci information to slack - with PR', async () => {
process.env.GITLAB_CI=true
process.env.CI_OPEN_MERGE_REQUESTS='testbeats/demo!1'
process.env.CI_PROJECT_URL = 'https://gitlab.com/testbeats/demo'
process.env.CI_PROJECT_NAME = 'demo'
process.env.CI_COMMIT_REF_NAME = 'branch'
process.env.CI_COMMIT_SHA = 'sha'
process.env.CI_JOB_URL = 'https://gitlab.com/testbeats/demo/-/jobs/id-123'
process.env.CI_JOB_ID = 'id-123'
process.env.CI_JOB_NAME = 'Test'
process.env.CI_PIPELINE_SOURCE = 'push'
process.env.GITLAB_CI = true;
process.env.CI_OPEN_MERGE_REQUESTS = 'testbeats/demo!1';
process.env.CI_PROJECT_URL = 'https://gitlab.com/testbeats/demo';
process.env.CI_PROJECT_NAME = 'demo';
process.env.CI_COMMIT_REF_NAME = 'branch';
process.env.CI_COMMIT_SHA = 'sha';
process.env.CI_JOB_URL = 'https://gitlab.com/testbeats/demo/-/jobs/id-123';
process.env.CI_JOB_ID = 'id-123';
process.env.CI_JOB_NAME = 'Test';
process.env.CI_PIPELINE_SOURCE = 'push';
process.env.GITLAB_USER_LOGIN = 'dummy-user';

const id = mock.addInteraction('post test-summary with gitlab ci-info with PR to slack');
Expand Down Expand Up @@ -264,6 +274,46 @@ describe('extensions - ci-info', () => {
assert.equal(mock.getInteraction(id).exercised, true);
});

it('should send test-summary with circle-ci\'s ci information to slack', async () => {
process.env.CIRCLECI = true;
process.env.CIRCLE_REPOSITORY_URL = '';
process.env.CIRCLE_PROJECT_REPONAME = 'demo';
process.env.CIRCLE_BRANCH = 'branch';
process.env.CIRCLE_SHA1 = 'sja';
process.env.CIRCLE_BUILD_URL = 'https://apphttps://app.circleci.com/jobs/circleci/uuid-1/uuid-2';
process.env.CIRCLE_BUILD_NUM = 1;
process.env.CIRCLE_JOB = 'Test_Build';
process.env.CIRCLE_USERNAME = '[email protected]';

const id = mock.addInteraction('post test-summary with circle-ci ci-info to slack');
await publish({
config: {
targets: [
{
name: 'slack',
inputs: {
url: 'http://localhost:9393/message'
},
extensions: [
{
name: 'ci-info'
}
]
}
],
results: [
{
type: 'testng',
files: [
'test/data/testng/single-suite.xml'
]
}
]
}
});
assert.equal(mock.getInteraction(id).exercised, true);
});

it('should send test-summary with azure devops ci information to chat and extra data', async () => {
process.env.GITHUB_ACTIONS = 'GITHUB_ACTIONS';
process.env.GITHUB_SERVER_URL = 'https://github.com';
Expand Down
32 changes: 32 additions & 0 deletions test/mocks/slack.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,38 @@ addInteractionHandler('post test-summary with gitlab ci-info with PR to slack',
}
});

addInteractionHandler('post test-summary with circle-ci ci-info to slack', () => {
return {
request: {
method: 'POST',
path: '/message',
body: {
"attachments": [
{
"color": "#36A64F",
"blocks": [
{
"@DATA:TEMPLATE@": "SLACK_ROOT_SINGLE_SUITE"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Build:* <https://apphttps://app.circleci.com/jobs/circleci/uuid-1/uuid-2|Test_Build #1>"
}
}
],
"fallback": "Default suite\nResults: 4 / 4 Passed (100%)"
}
]
}
},
response: {
status: 200
}
}
});

addInteractionHandler('post test-summary with multiple suites and ci-info to to slack', () => {
return {
request: {
Expand Down

0 comments on commit 610c1a8

Please sign in to comment.