@@ -27,41 +27,26 @@ suite('testing the golang-go-modules data provider', () => {
2727 "go_mod_empty"
2828 ] . forEach ( testCase => {
2929 let scenario = testCase . replace ( 'go_mod_' , '' ) . replaceAll ( '_' , ' ' )
30- test ( `verify go.mod sbom provided for stack analysis with scenario ${ scenario } ` , async ( ) => {
31- // load the expected graph for the scenario
32- let expectedSbom = fs . readFileSync ( `test/providers/tst_manifests/golang/${ testCase } /expected_sbom_stack_analysis.json` ) . toString ( )
33- expectedSbom = JSON . stringify ( JSON . parse ( expectedSbom ) , null , 4 )
34- // invoke sut stack analysis for scenario manifest
35- let providedDataForStack = await golangGoModules . provideStack ( `test/providers/tst_manifests/golang/${ testCase } /go.mod` )
36- // new(year: number, month: number, date?: number, hours?: number, minutes?: number, seconds?: number, ms?: number): Date
37-
38- // providedDataForStack.content = providedDataForStack.content.replaceAll("\"timestamp\":\"[a-zA-Z0-9\\-\\:]+\"","")
39- // verify returned data matches expectation
40- expect ( providedDataForStack . ecosystem ) . equal ( 'golang' )
41- expect ( providedDataForStack . contentType ) . equal ( 'application/vnd.cyclonedx+json' )
42- expect ( JSON . stringify ( JSON . parse ( providedDataForStack . content ) , null , 4 ) . trim ( ) ) . to . deep . equal ( expectedSbom . trim ( ) )
43- // these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
44- } ) . timeout ( process . env . GITHUB_ACTIONS ? 30000 : 10000 )
45-
46- test ( `verify go.mod sbom provided for component analysis with scenario ${ scenario } ` , async ( ) => {
47- // load the expected list for the scenario
48- let expectedSbom = fs . readFileSync ( `test/providers/tst_manifests/golang/${ testCase } /expected_sbom_component_analysis.json` ) . toString ( ) . trimEnd ( )
49- expectedSbom = JSON . stringify ( JSON . parse ( expectedSbom ) , null , 4 )
50- // invoke sut stack analysis for scenario manifest
51- let providedDataForComponent = await golangGoModules . provideComponent ( `test/providers/tst_manifests/golang/${ testCase } /go.mod` )
52- // verify returned data matches expectation
53- expect ( providedDataForComponent . ecosystem ) . equal ( 'golang' )
54- expect ( providedDataForComponent . contentType ) . equal ( 'application/vnd.cyclonedx+json' )
55- expect ( JSON . stringify ( JSON . parse ( providedDataForComponent . content ) , null , 4 ) . trimEnd ( ) ) . to . deep . equal ( expectedSbom )
56- // these test cases takes ~1400-2000 ms each pr >10000 in CI (for the first test-case)
57- } ) . timeout ( process . env . GITHUB_ACTIONS ? 15000 : 10000 )
58-
30+ ; [
31+ { type : 'stack' , method : 'provideStack' , fixture : 'expected_sbom_stack_analysis.json' , ciTimeout : 30000 } ,
32+ { type : 'component' , method : 'provideComponent' , fixture : 'expected_sbom_component_analysis.json' , ciTimeout : 15000 }
33+ ] . forEach ( ( { type, method, fixture, ciTimeout} ) => {
34+ test ( `verify go.mod sbom provided for ${ type } analysis with scenario ${ scenario } ` , async ( ) => {
35+ let expectedSbom = fs . readFileSync ( `test/providers/tst_manifests/golang/${ testCase } /${ fixture } ` ) . toString ( )
36+ expectedSbom = JSON . stringify ( JSON . parse ( expectedSbom ) , null , 4 )
37+ let providedData = await golangGoModules [ method ] ( `test/providers/tst_manifests/golang/${ testCase } /go.mod` )
38+ expect ( providedData . ecosystem ) . equal ( 'golang' )
39+ expect ( providedData . contentType ) . equal ( 'application/vnd.cyclonedx+json' )
40+ expect ( JSON . stringify ( JSON . parse ( providedData . content ) , null , 4 ) . trimEnd ( ) ) . to . deep . equal ( expectedSbom . trimEnd ( ) )
41+ } ) . timeout ( process . env . GITHUB_ACTIONS ? ciTimeout : 10000 )
42+ } )
5943 } ) ;
6044
6145 test ( 'verify go_mod_no_ignore component analysis includes all root-level deps from go mod graph' , async ( ) => {
6246 let providedData = await golangGoModules . provideComponent ( 'test/providers/tst_manifests/golang/go_mod_no_ignore/go.mod' )
6347 let sbom = JSON . parse ( providedData . content )
64- let rootDeps = sbom . dependencies . find ( d => d . dependsOn && d . dependsOn . length > 0 )
48+ let rootRef = sbom . metadata . component . purl
49+ let rootDeps = sbom . dependencies . find ( d => d . ref === rootRef )
6550 expect ( rootDeps . dependsOn ) . to . have . lengthOf ( 45 ,
6651 'Component analysis should include all root-level edges from go mod graph as direct deps. ' +
6752 'A lower count indicates the directDepPaths filtering is incorrectly excluding indirect require entries.' )
0 commit comments