-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DT-208 Adds unit test suite to policies
- Loading branch information
1 parent
d79018e
commit 077639f
Showing
7 changed files
with
112 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
name: Continuous Integration | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
|
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,32 @@ | ||
import { CopyleftPolicyCheck } from '../src/policies/copyleft-policy-check'; | ||
import { CONCLUSION, PolicyCheck } from '../src/policies/policy-check'; | ||
import { ScannerResults } from '../src/services/result.interfaces'; | ||
import * as github from '@actions/github'; | ||
import { resultsMock } from './results.mock'; | ||
|
||
describe('CopyleftPolicyCheck', () => { | ||
let scannerResults: ScannerResults; | ||
let policyCheck: CopyleftPolicyCheck; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
jest.spyOn(github, 'getOctokit').mockImplementation(); | ||
jest.spyOn(PolicyCheck.prototype, 'run').mockImplementation(); | ||
jest.spyOn(PolicyCheck.prototype, 'finish').mockImplementation(); | ||
|
||
policyCheck = new CopyleftPolicyCheck(); | ||
}); | ||
|
||
it('should pass the policy check when no copyleft components are found', async () => { | ||
scannerResults = JSON.parse(resultsMock[0].content); | ||
await policyCheck.run(scannerResults); | ||
expect(policyCheck.conclusion).toEqual(CONCLUSION.Success); | ||
}); | ||
|
||
it('should fail the policy check when copyleft components are found', async () => { | ||
scannerResults = JSON.parse(resultsMock[2].content); | ||
await policyCheck.run(scannerResults); | ||
expect(policyCheck.conclusion).toEqual(CONCLUSION.Neutral); | ||
}); | ||
}); |
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
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,20 @@ | ||
import { Sbom } from '../src/utils/sbom.utils'; | ||
|
||
export const sbomMock: Sbom[] = [ | ||
{ | ||
components: [] // empty sbom | ||
}, | ||
{ | ||
components: [ | ||
{ purl: 'pkg:github/scanoss/engine' }, | ||
{ purl: 'pkg:github/scanoss/engine' }, | ||
{ purl: 'pkg:github/scanoss/engine' }, | ||
{ purl: 'pkg:pypi/requests' }, | ||
{ purl: 'pkg:pypi/crc32c' }, | ||
{ purl: 'pkg:pypi/binaryornot' }, | ||
{ purl: 'pkg:pypi/pytest' }, | ||
{ purl: 'pkg:pypi/pytest-cov' }, | ||
{ purl: 'pkg:pypi/beautifulsoup4' } | ||
] | ||
} | ||
]; |
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,39 @@ | ||
import { CONCLUSION, PolicyCheck } from '../src/policies/policy-check'; | ||
import { ScannerResults } from '../src/services/result.interfaces'; | ||
import * as github from '@actions/github'; | ||
import { resultsMock } from './results.mock'; | ||
import { UndeclaredPolicyCheck } from '../src/policies/undeclared-policy-check'; | ||
import * as sbom from '../src/utils/sbom.utils'; | ||
import { sbomMock } from './sbom.mock'; | ||
|
||
describe('UndeclaredPolicyCheck', () => { | ||
let scannerResults: ScannerResults; | ||
let undeclaredPolicyCheck: UndeclaredPolicyCheck; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
jest.spyOn(github, 'getOctokit').mockImplementation(); | ||
|
||
jest.spyOn(PolicyCheck.prototype, 'run').mockImplementation(); | ||
jest.spyOn(PolicyCheck.prototype, 'finish').mockImplementation(); | ||
|
||
scannerResults = JSON.parse(resultsMock[3].content); | ||
|
||
undeclaredPolicyCheck = new UndeclaredPolicyCheck(); | ||
}); | ||
|
||
it('should pass the policy check when undeclared components are not found', async () => { | ||
jest.spyOn(sbom, 'parseSbom').mockImplementation(async _ => Promise.resolve(sbomMock[1])); | ||
Check warning on line 27 in __tests__/undeclared-policy-check.test.ts GitHub Actions / TypeScript Tests
|
||
|
||
await undeclaredPolicyCheck.run(scannerResults); | ||
expect(undeclaredPolicyCheck.conclusion).toEqual(CONCLUSION.Success); | ||
}); | ||
|
||
it('should fail the policy check when undeclared components are found', async () => { | ||
jest.spyOn(sbom, 'parseSbom').mockImplementation(async _ => Promise.resolve(sbomMock[0])); | ||
Check warning on line 34 in __tests__/undeclared-policy-check.test.ts GitHub Actions / TypeScript Tests
|
||
|
||
await undeclaredPolicyCheck.run(scannerResults); | ||
expect(undeclaredPolicyCheck.conclusion).toEqual(CONCLUSION.Neutral); | ||
}); | ||
}); |
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