-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(informative test): #205 replaced test csaf files by template lite…
…rals in the code
- Loading branch information
1 parent
18098b4
commit 05ba3ae
Showing
4 changed files
with
114 additions
and
156 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,51 +1,129 @@ | ||
import { expect } from 'chai' | ||
import informativeTest_6_3_8 from '../lib/informativeTests/informativeTest_6_3_8.js' | ||
import readExampleFiles from './shared/readExampleFiles.js' | ||
|
||
const validString = "Mocked as Valid" | ||
const validMarker = 'Mocked as Valid' | ||
|
||
const failingExamples = await readExampleFiles( | ||
new URL('informativeTest_6_3_8/failing', import.meta.url) | ||
) | ||
const documentValidBasePart = `category": "csaf_base", | ||
"csaf_version": "2.0", | ||
"lang": "en", | ||
"notes": [ | ||
{ | ||
"category": "summary", | ||
"text": "${validMarker}" | ||
} | ||
], | ||
"publisher": { | ||
"category": "other", | ||
"name": "OASIS CSAF TC [${validMarker}]", | ||
"namespace": "https://example.com" | ||
},` | ||
|
||
const validExamples = await readExampleFiles( | ||
new URL('informativeTest_6_3_8/valid', import.meta.url) | ||
) | ||
const validTrackingpart = `"tracking": { | ||
"current_release_date": "2021-07-21T10:00:00.000Z", | ||
"id": "OASIS_CSAF_TC-CSAF_2.0-2021-6-3-08-01", | ||
"initial_release_date": "2021-07-21T10:00:00.000Z", | ||
"revision_history": [ | ||
{ | ||
"date": "2021-07-21T10:00:00.000Z", | ||
"number": "1", | ||
"summary": "${validMarker}" | ||
} | ||
], | ||
"status": "final", | ||
"version": "1" | ||
} | ||
}` | ||
|
||
/** | ||
* @param {object} params | ||
* @param {string} params.input | ||
* @returns | ||
*/ | ||
async function runHunspellMock({ input }) { | ||
if (input.includes(validMarker)) { | ||
return 'Hunspell vMOCK\n\n*' | ||
} else { | ||
return 'Hunspell vMOCK\n\n# wrongword 1' | ||
} | ||
} | ||
|
||
describe('Informative test 6.3.8', function () { | ||
describe('failing examples', function () { | ||
for (const [title, failingExample] of failingExamples) { | ||
it(title, async function () { | ||
const result = await informativeTest_6_3_8(failingExample, { | ||
async hunspell({ dictionary, input }) { | ||
if (input.includes(validString)) { | ||
return 'Hunspell vMOCK\n\n*' | ||
} else { | ||
return 'Hunspell vMOCK\n\n# wrongword 1' | ||
const csafWithInvalidTitle = `{ | ||
"document": { | ||
"${documentValidBasePart} | ||
"title": "Informative test: Spell check (failing example 1)[Mocked as Invalid]", | ||
${validTrackingpart} | ||
}` | ||
|
||
const csafWithInvalidProductName = `{ | ||
"document": { | ||
"${documentValidBasePart} | ||
"title": "Informative test: Spell check (failing example 1)[${validMarker}]", | ||
${validTrackingpart}, | ||
"product_tree": { | ||
"branches": [ | ||
{ | ||
"branches": [ | ||
{ | ||
"branches": [ | ||
{ | ||
"category": "product_name", | ||
"name": "Mocked as Invalid", | ||
"product": { | ||
"name": "${validMarker}", | ||
"product_id": "7Client-7.6", | ||
"product_identification_helper": { | ||
"cpe": "cpe:/o:redhat:enterprise_linux:7::client" | ||
} | ||
} | ||
} | ||
], | ||
"category": "product_family", | ||
"name": "${validMarker}" | ||
} | ||
], | ||
"category": "vendor", | ||
"name": "${validMarker}" | ||
} | ||
}, | ||
}) | ||
] | ||
} | ||
}` | ||
|
||
expect(result.infos).to.have.length.greaterThan(0) | ||
}) | ||
} | ||
describe('failing examples', function () { | ||
it('test invalid title', async function () { | ||
const result = await informativeTest_6_3_8( | ||
JSON.parse(csafWithInvalidTitle), | ||
{ | ||
hunspell: runHunspellMock, | ||
} | ||
) | ||
expect(result.infos).to.have.length.greaterThan(0) | ||
}) | ||
|
||
it('test invalid product name in branch', async function () { | ||
const result = await informativeTest_6_3_8( | ||
JSON.parse(csafWithInvalidProductName), | ||
{ | ||
hunspell: runHunspellMock, | ||
} | ||
) | ||
expect(result.infos).to.have.length.greaterThan(0) | ||
}) | ||
}) | ||
|
||
describe('valid examples', function () { | ||
for (const [title, validExample] of validExamples) { | ||
it(title, async function () { | ||
const result = await informativeTest_6_3_8(validExample, { | ||
async hunspell({ dictionary, input }) { | ||
if (input.includes(validString)) { | ||
return 'Hunspell vMOCK\n\n*' | ||
} else { | ||
return 'Hunspell vMOCK\n\n# wrongword 1' | ||
} | ||
}, | ||
}) | ||
const validCsaf = `{ | ||
"document": { | ||
"${documentValidBasePart} | ||
"title": "Informative test: Spell check (failing example 1)[Mocked as Invalid]", | ||
${validTrackingpart} | ||
}` | ||
|
||
expect(result.infos.length).to.equal(0) | ||
describe('valid examples', function () { | ||
it('test valid csaf', async function () { | ||
const result = await informativeTest_6_3_8(JSON.parse(validCsaf), { | ||
hunspell: runHunspellMock, | ||
}) | ||
} | ||
expect(result.infos).to.have.length.greaterThan(0) | ||
}) | ||
}) | ||
}) |
33 changes: 0 additions & 33 deletions
33
tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-01.json
This file was deleted.
Oops, something went wrong.
54 changes: 0 additions & 54 deletions
54
tests/informativeTest_6_3_8/failing/test_with_mocked_hunspell-csaf_2_0-2025-6-3-08-02.json
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
tests/informativeTest_6_3_8/valid/test_with_mocked_hunspell-csaf_2_0-2021-6-3-08-11.json
This file was deleted.
Oops, something went wrong.