fix sbom test error

Signed-off-by: Brian DeHamer <[email protected]>
This commit is contained in:
Brian DeHamer
2026-02-18 10:23:59 -08:00
parent 023c0c6795
commit 2ee9744a24
+14 -1
View File
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals'
import fs from 'fs/promises'
import os from 'os'
import path from 'path'
@@ -17,10 +18,22 @@ describe('parseSBOMFromPath', () => {
describe('file handling', () => {
it('should throw when file does not exist', async () => {
await expect(parseSBOMFromPath('/nonexistent/file.json')).rejects.toThrow(
/ENOENT/
/SBOM file not found/
)
})
it('should rethrow non-ENOENT errors', async () => {
const statSpy = jest.spyOn(fs, 'stat').mockRejectedValueOnce(
Object.assign(new Error('Permission denied'), { code: 'EACCES' })
)
await expect(parseSBOMFromPath('/some/file.json')).rejects.toThrow(
/Permission denied/
)
statSpy.mockRestore()
})
it('should throw when file contains invalid JSON', async () => {
const filePath = path.join(tempDir, 'invalid.json')
await fs.writeFile(filePath, 'not valid json')