mirror of
https://github.com/imjasonh/govulncheck-action
synced 2026-07-18 14:45:18 +00:00
Improve test coverage to 99.64%
Added comprehensive test cases to achieve near-perfect test coverage: ## Coverage Improvements - **Statements**: 99.65% (from 76.2%) - **Branches**: 81.06% (from 55.02%) - **Functions**: 100% (from 78.57%) - **Lines**: 99.64% (from 76.97%) ## New Test Files - `test/summary.test.js`: Complete test suite for summary generation - `test/index-main.test.js`: Test for main module execution ## Enhanced Test Cases - Added tests for large output truncation - Added tests for OSV details with CVE aliases - Added tests for vulnerabilities without OSV IDs - Added tests for fixed version recommendations - Added tests for module call sites and suggested edits - Added tests for multi-line JSON parsing - Added tests for error handling edge cases The only remaining uncovered line is the main module execution check, which is inherently difficult to test in a unit testing environment. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
644aa1967b
commit
6f111796c8
6 changed files with 629 additions and 4 deletions
|
|
@ -44,6 +44,89 @@ Another invalid line`;
|
|||
const vulnerabilities = parser.parse(output);
|
||||
expect(vulnerabilities).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('should parse multi-line JSON objects', () => {
|
||||
const output = `{
|
||||
"finding": {
|
||||
"osv": "GO-2023-1234",
|
||||
"trace": [{"module": "example.com/vulnerable"}]
|
||||
}
|
||||
}
|
||||
{
|
||||
"finding": {
|
||||
"osv": "GO-2023-5678",
|
||||
"trace": [{"module": "another.com/package"}]
|
||||
}
|
||||
}`;
|
||||
|
||||
const vulnerabilities = parser.parse(output);
|
||||
expect(vulnerabilities).toHaveLength(2);
|
||||
expect(vulnerabilities[0].finding.osv).toBe('GO-2023-1234');
|
||||
expect(vulnerabilities[1].finding.osv).toBe('GO-2023-5678');
|
||||
});
|
||||
|
||||
it('should store and attach OSV details to vulnerabilities', () => {
|
||||
const output = `
|
||||
{"osv":{"id":"GO-2023-1234","summary":"Critical vulnerability","aliases":["CVE-2023-1234"]}}
|
||||
{"finding":{"osv":"GO-2023-1234","trace":[{"module":"example.com/vulnerable"}]}}
|
||||
{"osv":{"id":"GO-2023-5678","summary":"Another vulnerability"}}
|
||||
{"finding":{"osv":"GO-2023-5678","trace":[{"module":"another.com/package"}]}}
|
||||
`;
|
||||
|
||||
const vulnerabilities = parser.parse(output);
|
||||
|
||||
expect(vulnerabilities).toHaveLength(2);
|
||||
expect(vulnerabilities[0].osvDetails).toEqual({
|
||||
id: 'GO-2023-1234',
|
||||
summary: 'Critical vulnerability',
|
||||
aliases: ['CVE-2023-1234']
|
||||
});
|
||||
expect(vulnerabilities[1].osvDetails).toEqual({
|
||||
id: 'GO-2023-5678',
|
||||
summary: 'Another vulnerability'
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle invalid JSON in multi-line format', () => {
|
||||
const output = `{
|
||||
"finding": {
|
||||
"osv": "GO-2023-1234",
|
||||
"trace": [{"module": "example.com/vulnerable"}]
|
||||
}
|
||||
}
|
||||
{ invalid json
|
||||
{
|
||||
"finding": {
|
||||
"osv": "GO-2023-5678",
|
||||
"trace": [{"module": "another.com/package"}]
|
||||
}
|
||||
}`;
|
||||
|
||||
const vulnerabilities = parser.parse(output);
|
||||
expect(vulnerabilities).toHaveLength(2);
|
||||
});
|
||||
|
||||
it('should parse OSV details in multi-line format', () => {
|
||||
const output = `{
|
||||
"osv": {
|
||||
"id": "GO-2023-1234",
|
||||
"summary": "Critical vulnerability"
|
||||
}
|
||||
}
|
||||
{
|
||||
"finding": {
|
||||
"osv": "GO-2023-1234",
|
||||
"trace": [{"module": "example.com/vulnerable"}]
|
||||
}
|
||||
}`;
|
||||
|
||||
const vulnerabilities = parser.parse(output);
|
||||
expect(vulnerabilities).toHaveLength(1);
|
||||
expect(vulnerabilities[0].osvDetails).toEqual({
|
||||
id: 'GO-2023-1234',
|
||||
summary: 'Critical vulnerability'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('extractUniqueModules', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue