forked from graalvm/setup-graalvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
133 additions
and
221 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
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,9 +1,9 @@ | ||
import * as c from '../src/constants' | ||
import { | ||
setUpSBOMSupport, | ||
processSBOM, | ||
mapToComponentsWithDependencies, | ||
INPUT_NI_SBOM, | ||
NATIVE_IMAGE_OPTIONS_ENV | ||
INPUT_NI_SBOM | ||
} from '../src/features/sbom' | ||
import * as core from '@actions/core' | ||
import * as github from '@actions/github' | ||
|
@@ -50,10 +50,8 @@ describe('sbom feature', () => { | |
let originalEnv: NodeJS.ProcessEnv | ||
|
||
beforeEach(() => { | ||
// Save original env | ||
originalEnv = process.env | ||
|
||
// Set up test environment | ||
process.env = { | ||
...process.env, | ||
GITHUB_REPOSITORY: 'test-owner/test-repo', | ||
|
@@ -93,7 +91,7 @@ describe('sbom feature', () => { | |
it('should set the SBOM option flag when activated', () => { | ||
setUpSBOMSupport() | ||
expect(spyExportVariable).toHaveBeenCalledWith( | ||
NATIVE_IMAGE_OPTIONS_ENV, | ||
c.NATIVE_IMAGE_OPTIONS_ENV, | ||
expect.stringContaining('--enable-sbom=export') | ||
) | ||
expect(spyInfo).toHaveBeenCalledWith( | ||
|
@@ -169,6 +167,9 @@ describe('sbom feature', () => { | |
expect(spyInfo).toHaveBeenCalledWith( | ||
'- pkg:maven/com.oracle/[email protected]' | ||
) | ||
expect(spyInfo).toHaveBeenCalledWith( | ||
' depends on: pkg:maven/org.json/json@20211205' | ||
) | ||
expect(spyWarning).not.toHaveBeenCalled() | ||
}) | ||
|
||
|
@@ -196,9 +197,8 @@ describe('sbom feature', () => { | |
await processSBOM() | ||
|
||
expect(spyInfo).toHaveBeenCalledWith('=== SBOM Content ===') | ||
expect(spyInfo).toHaveBeenCalledWith( | ||
'- [email protected] (purl not specified, component will not be submitted to GitHub dependency API)' | ||
) | ||
expect(spyInfo).toHaveBeenCalledWith('- [email protected]') | ||
expect(spyWarning).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('should handle missing SBOM file', async () => { | ||
|
@@ -209,7 +209,7 @@ describe('sbom feature', () => { | |
|
||
await processSBOM() | ||
expect(spyWarning).toHaveBeenCalledWith( | ||
'No SBOM file found. Make sure native-image build completed successfully.' | ||
'No SBOM file found. Make sure native-image build completed successfully. Skipping submission to GitHub Dependency API.' | ||
) | ||
}) | ||
|
||
|
@@ -241,7 +241,22 @@ describe('sbom feature', () => { | |
correlator: 'test-workflow_test-job', | ||
id: '12345' | ||
}), | ||
manifests: expect.any(Object) | ||
manifests: expect.objectContaining({ | ||
'test.sbom.json': expect.objectContaining({ | ||
name: 'test.sbom.json', | ||
resolved: expect.objectContaining({ | ||
json: expect.objectContaining({ | ||
package_url: 'pkg:maven/org.json/json@20211205', | ||
dependencies: [] | ||
}), | ||
'main-test-app': expect.objectContaining({ | ||
package_url: | ||
'pkg:maven/com.oracle/[email protected]', | ||
dependencies: ['pkg:maven/org.json/json@20211205'] | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
) | ||
}) | ||
|
@@ -267,94 +282,4 @@ describe('sbom feature', () => { | |
) | ||
}) | ||
}) | ||
|
||
describe('mapToComponents', () => { | ||
it('should map valid SBOM data to components', () => { | ||
const sbomData = { | ||
components: [ | ||
{ | ||
name: 'json', | ||
version: '20211205', | ||
purl: 'pkg:maven/org.json/json@20211205', | ||
'bom-ref': 'pkg:maven/org.json/json@20211205' | ||
}, | ||
{ | ||
name: 'main-test-app', | ||
version: '1.0-SNAPSHOT', | ||
purl: 'pkg:maven/com.oracle/[email protected]', | ||
'bom-ref': 'pkg:maven/com.oracle/[email protected]' | ||
} | ||
], | ||
dependencies: [ | ||
{ | ||
ref: 'pkg:maven/com.oracle/[email protected]', | ||
dependsOn: ['pkg:maven/org.json/json@20211205'] | ||
}, | ||
{ | ||
ref: 'pkg:maven/org.json/json@20211205', | ||
dependsOn: [] | ||
} | ||
] | ||
} | ||
|
||
const result = mapToComponentsWithDependencies(sbomData) | ||
|
||
expect(result).toEqual([ | ||
{ | ||
name: 'json', | ||
version: '20211205', | ||
purl: 'pkg:maven/org.json/json@20211205', | ||
dependencies: [], | ||
'bom-ref': 'pkg:maven/org.json/json@20211205' | ||
}, | ||
{ | ||
name: 'main-test-app', | ||
version: '1.0-SNAPSHOT', | ||
purl: 'pkg:maven/com.oracle/[email protected]', | ||
dependencies: ['pkg:maven/org.json/json@20211205'], | ||
'bom-ref': 'pkg:maven/com.oracle/[email protected]' | ||
} | ||
]) | ||
}) | ||
|
||
it('should handle components without dependencies', () => { | ||
const sbomData = { | ||
components: [ | ||
{ | ||
name: 'json', | ||
version: '20211205', | ||
purl: 'pkg:maven/org.json/json@20211205', | ||
'bom-ref': 'pkg:maven/org.json/json@20211205' | ||
} | ||
], | ||
dependencies: [] | ||
} | ||
|
||
const result = mapToComponentsWithDependencies(sbomData) | ||
|
||
expect(result).toEqual([ | ||
{ | ||
name: 'json', | ||
version: '20211205', | ||
purl: 'pkg:maven/org.json/json@20211205', | ||
dependencies: [], | ||
'bom-ref': 'pkg:maven/org.json/json@20211205' | ||
} | ||
]) | ||
}) | ||
|
||
it('should handle missing components', () => { | ||
const sbomData = { | ||
components: [], | ||
dependencies: [] | ||
} | ||
|
||
const result = mapToComponentsWithDependencies(sbomData) | ||
|
||
expect(result).toEqual([]) | ||
expect(spyWarning).toHaveBeenCalledWith( | ||
'Invalid SBOM data or no components found.' | ||
) | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.