-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for `lint` workflow See: #13604
- Loading branch information
1 parent
1894bc2
commit a7598f9
Showing
5 changed files
with
289 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const utils = require('../utils/utils'); | ||
|
||
const assertLintJobExecuted = (workflowResult, didExecute = true) => { | ||
const steps = [ | ||
utils.getStepAssertion( | ||
'Checkout', | ||
true, | ||
null, | ||
'LINT', | ||
'Checkout', | ||
[], | ||
[], | ||
), | ||
utils.getStepAssertion( | ||
'Setup Node', | ||
true, | ||
null, | ||
'LINT', | ||
'Setup Node', | ||
[], | ||
[], | ||
), | ||
utils.getStepAssertion( | ||
'Lint JavaScript with ESLint', | ||
true, | ||
null, | ||
'LINT', | ||
'Lint JavaScript with ESLint', | ||
[], | ||
[{key: 'CI', value: 'true'}], | ||
), | ||
utils.getStepAssertion( | ||
'Lint shell scripts with ShellCheck', | ||
true, | ||
null, | ||
'LINT', | ||
'Lint shell scripts with ShellCheck', | ||
[], | ||
[], | ||
), | ||
]; | ||
|
||
for (const expectedStep of steps) { | ||
if (didExecute) { | ||
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep])); | ||
} else { | ||
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep])); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = { | ||
assertLintJobExecuted, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
const path = require('path'); | ||
const kieMockGithub = require('@kie/mock-github'); | ||
const utils = require('./utils/utils'); | ||
const assertions = require('./assertions/lintAssertions'); | ||
const mocks = require('./mocks/lintMocks'); | ||
const eAct = require('./utils/ExtendedAct'); | ||
|
||
jest.setTimeout(60 * 1000); | ||
let mockGithub; | ||
const FILES_TO_COPY_INTO_TEST_REPO = [ | ||
{ | ||
src: path.resolve(__dirname, '..', '.github', 'actions'), | ||
dest: '.github/actions', | ||
}, | ||
{ | ||
src: path.resolve(__dirname, '..', '.github', 'libs'), | ||
dest: '.github/libs', | ||
}, | ||
{ | ||
src: path.resolve(__dirname, '..', '.github', 'scripts'), | ||
dest: '.github/scripts', | ||
}, | ||
{ | ||
src: path.resolve(__dirname, '..', '.github', 'workflows', 'lint.yml'), | ||
dest: '.github/workflows/lint.yml', | ||
}, | ||
]; | ||
|
||
describe('test workflow lint', () => { | ||
const githubToken = 'dummy_github_token'; | ||
const actor = 'Dummy Actor'; | ||
beforeEach(async () => { | ||
// create a local repository and copy required files | ||
mockGithub = new kieMockGithub.MockGithub({ | ||
repo: { | ||
testLintWorkflowRepo: { | ||
files: FILES_TO_COPY_INTO_TEST_REPO, | ||
|
||
// if any branches besides main are need add: pushedBranches: ['staging', 'production'], | ||
}, | ||
}, | ||
}); | ||
|
||
await mockGithub.setup(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await mockGithub.teardown(); | ||
}); | ||
describe('event is workflow_call', () => { | ||
const event = 'workflow_call'; | ||
const eventOptions = {}; | ||
it('runs the lint', async () => { | ||
const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; | ||
const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); | ||
let act = new eAct.ExtendedAct(repoPath, workflowPath); | ||
act = utils.setUpActParams( | ||
act, | ||
event, | ||
eventOptions, | ||
{}, | ||
githubToken, | ||
); | ||
const testMockSteps = { | ||
lint: mocks.LINT__LINT__STEP_MOCKS, | ||
}; | ||
const result = await act | ||
.runEvent(event, { | ||
workflowFile: path.join(repoPath, '.github', 'workflows'), | ||
mockSteps: testMockSteps, | ||
actor, | ||
}); | ||
|
||
assertions.assertLintJobExecuted(result); | ||
}); | ||
describe('actor is OSBotify', () => { | ||
const testActor = 'OSBotify'; | ||
it('runs the lint', async () => { | ||
const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; | ||
const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); | ||
let act = new eAct.ExtendedAct(repoPath, workflowPath); | ||
act = utils.setUpActParams( | ||
act, | ||
event, | ||
eventOptions, | ||
{}, | ||
githubToken, | ||
); | ||
const testMockSteps = { | ||
lint: mocks.LINT__LINT__STEP_MOCKS, | ||
}; | ||
const result = await act | ||
.runEvent(event, { | ||
workflowFile: path.join(repoPath, '.github', 'workflows'), | ||
mockSteps: testMockSteps, | ||
actor: testActor, | ||
}); | ||
|
||
assertions.assertLintJobExecuted(result); | ||
}); | ||
}); | ||
}); | ||
describe('event is pull_request', () => { | ||
const event = 'pull_request'; | ||
describe('pull_request is opened', () => { | ||
const eventOptions = { | ||
action: 'opened', | ||
}; | ||
it('runs the lint', async () => { | ||
const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; | ||
const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); | ||
let act = new eAct.ExtendedAct(repoPath, workflowPath); | ||
act = utils.setUpActParams( | ||
act, | ||
event, | ||
eventOptions, | ||
{}, | ||
githubToken, | ||
); | ||
const testMockSteps = { | ||
lint: mocks.LINT__LINT__STEP_MOCKS, | ||
}; | ||
const result = await act | ||
.runEvent(event, { | ||
workflowFile: path.join(repoPath, '.github', 'workflows'), | ||
mockSteps: testMockSteps, | ||
actor, | ||
}); | ||
|
||
assertions.assertLintJobExecuted(result); | ||
}); | ||
describe('actor is OSBotify', () => { | ||
const testActor = 'OSBotify'; | ||
it('does not run the lint', async () => { | ||
const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; | ||
const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); | ||
let act = new eAct.ExtendedAct(repoPath, workflowPath); | ||
act = utils.setUpActParams( | ||
act, | ||
event, | ||
eventOptions, | ||
{}, | ||
githubToken, | ||
); | ||
const testMockSteps = { | ||
lint: mocks.LINT__LINT__STEP_MOCKS, | ||
}; | ||
const result = await act | ||
.runEvent(event, { | ||
workflowFile: path.join(repoPath, '.github', 'workflows'), | ||
mockSteps: testMockSteps, | ||
actor: testActor, | ||
}); | ||
|
||
assertions.assertLintJobExecuted(result, false); | ||
}); | ||
}); | ||
}); | ||
describe('pull_request is synchronized', () => { | ||
const eventOptions = { | ||
action: 'synchronize', | ||
}; | ||
it('runs the lint', async () => { | ||
const repoPath = mockGithub.repo.getPath('testLintWorkflowRepo') || ''; | ||
const workflowPath = path.join(repoPath, '.github', 'workflows', 'lint.yml'); | ||
let act = new eAct.ExtendedAct(repoPath, workflowPath); | ||
act = utils.setUpActParams( | ||
act, | ||
event, | ||
eventOptions, | ||
{}, | ||
githubToken, | ||
); | ||
const testMockSteps = { | ||
lint: mocks.LINT__LINT__STEP_MOCKS, | ||
}; | ||
const result = await act | ||
.runEvent(event, { | ||
workflowFile: path.join(repoPath, '.github', 'workflows'), | ||
mockSteps: testMockSteps, | ||
actor, | ||
}); | ||
|
||
assertions.assertLintJobExecuted(result); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const utils = require('../utils/utils'); | ||
|
||
// lint | ||
const LINT__LINT__CHECKOUT__STEP_MOCK = utils.getMockStep( | ||
'Checkout', | ||
'Checkout', | ||
'LINT', | ||
[], | ||
[], | ||
); | ||
const LINT__LINT__SETUP_NODE__STEP_MOCK = utils.getMockStep( | ||
'Setup Node', | ||
'Setup Node', | ||
'LINT', | ||
[], | ||
[], | ||
); | ||
const LINT__LINT__LINT_JAVASCRIPT_WITH_ESLINT__STEP_MOCK = utils.getMockStep( | ||
'Lint JavaScript with ESLint', | ||
'Lint JavaScript with ESLint', | ||
'LINT', | ||
[], | ||
['CI'], | ||
); | ||
const LINT__LINT__LINT_SHELL_SCRIPTS_WITH_SHELLCHECK__STEP_MOCK = utils.getMockStep( | ||
'Lint shell scripts with ShellCheck', | ||
'Lint shell scripts with ShellCheck', | ||
'LINT', | ||
[], | ||
[], | ||
); | ||
const LINT__LINT__STEP_MOCKS = [ | ||
LINT__LINT__CHECKOUT__STEP_MOCK, | ||
LINT__LINT__SETUP_NODE__STEP_MOCK, | ||
LINT__LINT__LINT_JAVASCRIPT_WITH_ESLINT__STEP_MOCK, | ||
LINT__LINT__LINT_SHELL_SCRIPTS_WITH_SHELLCHECK__STEP_MOCK, | ||
]; | ||
|
||
module.exports = { | ||
LINT__LINT__STEP_MOCKS, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters