1+ import { throws } from 'assert' ;
12import fs from 'fs'
23
34import { expect } from 'chai'
@@ -28,8 +29,8 @@ function getStubbedResponse(args, dependencyTreeTextContent, gradleProperties) {
2829suite ( 'testing the java-gradle-groovy data provider' , ( ) => {
2930
3031 [
31- { name : 'build.gradle' , expected : true } ,
32- { name : 'some_other.file' , expected : false }
32+ { name : 'build.gradle' , expected : true } ,
33+ { name : 'some_other.file' , expected : false }
3334 ] . forEach ( testCase => {
3435 test ( `verify isSupported returns ${ testCase . expected } for ${ testCase . name } ` , ( ) => {
3536 let javaGradleProvider = new Java_gradle_groovy ( )
@@ -41,7 +42,7 @@ suite('testing the java-gradle-groovy data provider', () => {
4142 "deps_with_no_ignore_common_paths" ,
4243 "deps_with_ignore_full_specification" ,
4344 "deps_with_ignore_named_params" ,
44- "deps_with_ignore_notations"
45+ "deps_with_ignore_notations" ,
4546 ] . forEach ( testCase => {
4647 let scenario = testCase . replaceAll ( '_' , ' ' )
4748
@@ -50,7 +51,7 @@ suite('testing the java-gradle-groovy data provider', () => {
5051 let expectedSbom = fs . readFileSync ( `test/providers/tst_manifests/gradle/${ testCase } /expected_stack_sbom.json` , ) . toString ( ) . trim ( )
5152 let dependencyTreeTextContent = fs . readFileSync ( `test/providers/tst_manifests/gradle/${ testCase } /depTree.txt` , ) . toString ( )
5253 let gradleProperties = fs . readFileSync ( `test/providers/tst_manifests/gradle/${ testCase } /gradle.properties` , ) . toString ( )
53- let mockedExecFunction = function ( bin , args ) {
54+ let mockedExecFunction = function ( bin , args ) {
5455 return getStubbedResponse ( args , dependencyTreeTextContent , gradleProperties ) ;
5556 }
5657 let provider = new Java_gradle_groovy ( )
@@ -60,25 +61,44 @@ suite('testing the java-gradle-groovy data provider', () => {
6061 // verify returned data matches expectation
6162 compareSboms ( providedDataForStack . content , expectedSbom ) ;
6263
63- // these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
64+ // these test cases takes ~2500-2700 ms each pr >10000 in CI (for the first test-case)
6465 } ) . timeout ( process . env . GITHUB_ACTIONS ? 40000 : 10000 )
6566
6667 test ( `verify gradle data provided for component analysis with scenario ${ scenario } ` , async ( ) => {
6768 // load the expected list for the scenario
6869 let expectedSbom = fs . readFileSync ( `test/providers/tst_manifests/gradle/${ testCase } /expected_component_sbom.json` , ) . toString ( ) . trim ( )
6970 let dependencyTreeTextContent = fs . readFileSync ( `test/providers/tst_manifests/gradle/${ testCase } /depTree.txt` , ) . toString ( )
7071 let gradleProperties = fs . readFileSync ( `test/providers/tst_manifests/gradle/${ testCase } /gradle.properties` , ) . toString ( )
71- let mockedExecFunction = function ( bin , args ) {
72+ let mockedExecFunction = function ( bin , args ) {
7273 return getStubbedResponse ( args , dependencyTreeTextContent , gradleProperties ) ;
7374 }
7475 let provider = new Java_gradle_groovy ( )
7576 Object . getPrototypeOf ( Object . getPrototypeOf ( provider ) ) . _invokeCommand = mockedExecFunction
76- // invoke sut component analysis for scenario manifest
77+ // invoke component analysis for scenario manifest
7778 let providedForComponent = provider . provideComponent ( `test/providers/tst_manifests/gradle/${ testCase } /build.gradle` , { } )
7879 // verify returned data matches expectation
7980 compareSboms ( providedForComponent . content , expectedSbom ) ;
8081 // these test cases takes ~1400-2000 ms each pr >10000 in CI (for the first test-case)
8182 } ) . timeout ( process . env . GITHUB_ACTIONS ? 15000 : 5000 )
83+ } ) ;
84+
85+ [
86+ "deps_with_empty_project_group"
87+ ] . forEach ( testCase => {
88+ let scenario = testCase . replaceAll ( '_' , ' ' )
89+
90+ test ( `verify gradle provider throws with scenario ${ scenario } ` , async ( ) => {
91+ // load the expected list for the scenario
92+ let dependencyTreeTextContent = fs . readFileSync ( `test/providers/tst_manifests/gradle/${ testCase } /depTree.txt` , ) . toString ( )
93+ let gradleProperties = fs . readFileSync ( `test/providers/tst_manifests/gradle/${ testCase } /gradle.properties` , ) . toString ( )
94+ let mockedExecFunction = function ( bin , args ) {
95+ return getStubbedResponse ( args , dependencyTreeTextContent , gradleProperties ) ;
96+ }
97+ let provider = new Java_gradle_groovy ( )
98+ Object . getPrototypeOf ( Object . getPrototypeOf ( provider ) ) . _invokeCommand = mockedExecFunction
99+ // invoke component analysis for scenario manifest
100+ throws ( ( ) => provider . provideComponent ( `test/providers/tst_manifests/gradle/${ testCase } /build.gradle` , { } ) )
101+ } )
82102 } )
83- } ) . beforeAll ( ( ) => clock = useFakeTimers ( new Date ( '2023-08-07T00:00:00.000Z' ) ) ) . afterAll ( ( ) => { clock . restore ( ) } ) ;
103+ } ) . beforeAll ( ( ) => clock = useFakeTimers ( new Date ( '2023-08-07T00:00:00.000Z' ) ) ) . afterAll ( ( ) => { clock . restore ( ) } ) ;
84104
0 commit comments