diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index d1e82aa..3d0692d 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -37,30 +37,8 @@ describe('action', () => { // Set the action's inputs as return values from core.getInput() getInputMock.mockImplementation((name: string): string => { switch (name) { - case 'milliseconds': - return '500'; - default: + case 'scanner-parameters': return ''; - } - }); - - await main.run(); - expect(runMock).toHaveReturned(); - - // Verify that all of the core library functions were called correctly - expect(debugMock).toHaveBeenNthCalledWith(1, 'Waiting 500 milliseconds ...'); - expect(debugMock).toHaveBeenNthCalledWith(2, expect.stringMatching(timeRegex)); - expect(debugMock).toHaveBeenNthCalledWith(3, expect.stringMatching(timeRegex)); - expect(setOutputMock).toHaveBeenNthCalledWith(1, 'time', expect.stringMatching(timeRegex)); - expect(errorMock).not.toHaveBeenCalled(); - }); - - it('sets a failed status', async () => { - // Set the action's inputs as return values from core.getInput() - getInputMock.mockImplementation((name: string): string => { - switch (name) { - case 'milliseconds': - return 'this is not a number'; default: return ''; } @@ -70,7 +48,7 @@ describe('action', () => { expect(runMock).toHaveReturned(); // Verify that all of the core library functions were called correctly - expect(setFailedMock).toHaveBeenNthCalledWith(1, 'milliseconds not a number'); + expect(debugMock).toHaveBeenNthCalledWith(1, 'SCANOSS Scan Action started...'); expect(errorMock).not.toHaveBeenCalled(); }); }); diff --git a/__tests__/report-service.test.ts b/__tests__/report-service.test.ts new file mode 100644 index 0000000..c665635 --- /dev/null +++ b/__tests__/report-service.test.ts @@ -0,0 +1,41 @@ +import { getLicensesReport } from '../src/services/report.service'; +import { ScannerResults } from '../src/services/result.interfaces'; +import { getLicenses, Licenses } from '../src/services/result.service'; + +const licenseTableTest = [ + { + name: '1) report test', + licenses: [{ spdxid: 'MIT', url: null, copyleft: null }], + output: '| License | Copyleft | URL |\n| ------- | -------- | --- |\n| MIT | :x: | |\n' + }, + { + name: '2) report test', + licenses: [ + { spdxid: 'MIT', url: null, copyleft: null }, + { spdxid: 'Apache-2.0', url: null, copyleft: null }, + { spdxid: '0BSD', url: null, copyleft: null } + ], + output: + '| License | Copyleft | URL |\n| ------- | -------- | --- |\n| MIT | :x: | |\n| Apache-2.0 | :x: | |\n| 0BSD | :x: | |\n' + }, + { + name: '3) report test', + licenses: [ + { spdxid: 'GPL-2.0-only', url: 'https://spdx.org/licenses/GPL-2.0-only.html', copyleft: true }, + { spdxid: 'GPL-2.0-or-later', url: 'https://spdx.org/licenses/GPL-2.0-or-later.html', copyleft: true }, + { spdxid: 'JSON', url: 'https://spdx.org/licenses/JSON.html', copyleft: null }, + { spdxid: 'LicenseRef-scancode-unknown-license-reference', url: null, copyleft: null } + ], + output: + '| License | Copyleft | URL |\n| ------- | -------- | --- |\n| GPL-2.0-only | :heavy_check_mark: | https://spdx.org/licenses/GPL-2.0-only.html |\n| GPL-2.0-or-later | :heavy_check_mark: | https://spdx.org/licenses/GPL-2.0-or-later.html |\n| JSON | :x: | https://spdx.org/licenses/JSON.html |\n| LicenseRef-scancode-unknown-license-reference | :x: | |\n' + } +]; + +describe('Test report service', () => { + for (const t of licenseTableTest) { + it(`${t.name}`, () => { + const report = getLicensesReport(t.licenses); + expect(report).toEqual(t.output); + }); + } +}); diff --git a/__tests__/report.service.test.ts b/__tests__/report.service.test.ts deleted file mode 100644 index 2ab008b..0000000 --- a/__tests__/report.service.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { ScannerResults } from '../src/services/result.interfaces'; -import { getLicenses, Licenses } from '../src/services/result.service'; -import { resultsMock } from './results.mock'; - -const licenseTableTest = [ - { - ...resultsMock[0], - licenses: [{ spdxid: 'MIT', url: null, copyleft: null }] - }, - { - ...resultsMock[1], - licenses: [ - { spdxid: 'MIT', url: null, copyleft: null }, - { spdxid: 'Apache-2.0', url: null, copyleft: null }, - { spdxid: '0BSD', url: null, copyleft: null } - ] - }, - { - ...resultsMock[2], - licenses: [ - { spdxid: 'GPL-2.0-only', url: 'https://spdx.org/licenses/GPL-2.0-only.html', copyleft: true }, - { spdxid: 'GPL-2.0-or-later', url: 'https://spdx.org/licenses/GPL-2.0-or-later.html', copyleft: true }, - { spdxid: 'JSON', url: 'https://spdx.org/licenses/JSON.html', copyleft: null }, - { spdxid: 'LicenseRef-scancode-unknown-license-reference', url: null, copyleft: null } - ] - }, - { - ...resultsMock[3], - licenses: [ - { spdxid: 'MIT', url: null, copyleft: null }, - { spdxid: 'GPL-2.0-only', url: 'https://spdx.org/licenses/GPL-2.0-only.html', copyleft: true }, - { spdxid: 'JSON', url: 'https://spdx.org/licenses/JSON.html', copyleft: null }, - { spdxid: 'LicenseRef-scancode-unknown-license-reference', url: null, copyleft: null }, - { spdxid: 'GPL-2.0-or-later', url: 'https://spdx.org/licenses/GPL-2.0-or-later.html', copyleft: true }, - { spdxid: 'Apache-2.0', url: null, copyleft: null }, - { spdxid: '0BSD', url: null, copyleft: null } - ] - } -]; - -describe('Test Results service', () => { - for (const t of licenseTableTest) { - it(`${t.name}`, () => { - const scannerResults = JSON.parse(t.content) as ScannerResults; - const licenses = getLicenses(scannerResults); - - const sortFn = (a: Licenses, b: Licenses): number => a.spdxid.localeCompare(b.spdxid); - expect(licenses.sort(sortFn)).toEqual(t.licenses.sort(sortFn)); - }); - } -}); diff --git a/__tests__/result.service.test.ts b/__tests__/result-service.test.ts similarity index 100% rename from __tests__/result.service.test.ts rename to __tests__/result-service.test.ts diff --git a/dist/index.js b/dist/index.js index 9858615..173b09f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -30191,9 +30191,11 @@ const report_service_1 = __nccwpck_require__(2467); */ async function run() { try { + core.debug(`SCANOSS Scan Action started...`); const repoDir = process.env.GITHUB_WORKSPACE; const outputPath = 'results.json'; // create policies + core.debug(`Creating policies`); const policies = [new license_policy_check_1.LicensePolicyCheck()]; policies.forEach(async (policy) => policy.start()); // run scan diff --git a/src/main.ts b/src/main.ts index 20a027f..8edfe6e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,10 +11,13 @@ import { getLicensesReport } from './services/report.service'; */ export async function run(): Promise { try { + core.debug(`SCANOSS Scan Action started...`); + const repoDir = process.env.GITHUB_WORKSPACE as string; const outputPath = 'results.json'; // create policies + core.debug(`Creating policies`); const policies = [new LicensePolicyCheck()]; policies.forEach(async policy => policy.start());