@@ -869,7 +869,7 @@ func TestAddSastScan(t *testing.T) {
869869 cmdCommand .PersistentFlags ().String (commonParams .PresetName , "" , "Preset name" )
870870 cmdCommand .PersistentFlags ().String (commonParams .SastFilterFlag , "" , "Filter for SAST scan" )
871871 cmdCommand .PersistentFlags ().Bool (commonParams .IncrementalSast , false , "Incremental SAST scan" )
872- cmdCommand .PersistentFlags ().Bool (commonParams .SastFastScanFlag , true , "Enable SAST Fast Scan" )
872+ cmdCommand .PersistentFlags ().Bool (commonParams .SastFastScanFlag , false , "Enable SAST Fast Scan" )
873873
874874 _ = cmdCommand .Execute ()
875875
@@ -883,7 +883,7 @@ func TestAddSastScan(t *testing.T) {
883883 PresetName : "test" ,
884884 Filter : "test" ,
885885 Incremental : "true" ,
886- FastScanMode : "true " ,
886+ FastScanMode : "" ,
887887 }
888888 sastMapConfig := make (map [string ]interface {})
889889 sastMapConfig [resultsMapType ] = commonParams .SastType
@@ -1766,6 +1766,129 @@ func TestUploadZip_whenUserNotProvideZip_shouldReturnZipFilePathInFailureCase(t
17661766 assert .Equal (t , zipPath , "failureCase.zip" )
17671767}
17681768
1769+ func TestAddSastScan_ScanFlags (t * testing.T ) {
1770+ var resubmitConfig []wrappers.Config
1771+
1772+ tests := []struct {
1773+ name string
1774+ requiredIncrementalSet bool
1775+ requiredFastScanSet bool
1776+ fastScanFlag string
1777+ incrementalFlag string
1778+ expectedConfig wrappers.SastConfig
1779+ }{
1780+ {
1781+ name : "Fast scan and Incremental scan both false" ,
1782+ requiredIncrementalSet : true ,
1783+ requiredFastScanSet : true ,
1784+ fastScanFlag : "false" ,
1785+ incrementalFlag : "false" ,
1786+ expectedConfig : wrappers.SastConfig {
1787+ FastScanMode : "false" ,
1788+ Incremental : "false" ,
1789+ },
1790+ },
1791+ {
1792+ name : "Fast scan and Incremental scan both true" ,
1793+ requiredIncrementalSet : true ,
1794+ requiredFastScanSet : true ,
1795+ fastScanFlag : "true" ,
1796+ incrementalFlag : "true" ,
1797+ expectedConfig : wrappers.SastConfig {
1798+ FastScanMode : "true" ,
1799+ Incremental : "true" ,
1800+ },
1801+ },
1802+ {
1803+ name : "Fast scan and Incremental not set" ,
1804+ requiredIncrementalSet : false ,
1805+ requiredFastScanSet : false ,
1806+ expectedConfig : wrappers.SastConfig {},
1807+ },
1808+ {
1809+ name : "Fast scan is true and Incremental is false" ,
1810+ requiredIncrementalSet : true ,
1811+ requiredFastScanSet : true ,
1812+ fastScanFlag : "true" ,
1813+ incrementalFlag : "false" ,
1814+ expectedConfig : wrappers.SastConfig {
1815+ FastScanMode : "true" ,
1816+ Incremental : "false" ,
1817+ },
1818+ },
1819+ {
1820+ name : "Fast scan is false and Incremental is true" ,
1821+ requiredIncrementalSet : true ,
1822+ requiredFastScanSet : true ,
1823+ fastScanFlag : "false" ,
1824+ incrementalFlag : "true" ,
1825+ expectedConfig : wrappers.SastConfig {
1826+ FastScanMode : "false" ,
1827+ Incremental : "true" ,
1828+ },
1829+ },
1830+ {
1831+ name : "Fast scan is not set and Incremental is true" ,
1832+ requiredIncrementalSet : true ,
1833+ incrementalFlag : "true" ,
1834+ expectedConfig : wrappers.SastConfig {
1835+ Incremental : "true" ,
1836+ },
1837+ },
1838+ {
1839+ name : "Fast scan is true and Incremental is not set" ,
1840+ requiredFastScanSet : true ,
1841+ fastScanFlag : "true" ,
1842+ expectedConfig : wrappers.SastConfig {
1843+ FastScanMode : "true" ,
1844+ },
1845+ },
1846+ }
1847+
1848+ oldActualScanTypes := actualScanTypes
1849+
1850+ defer func () {
1851+ actualScanTypes = oldActualScanTypes
1852+ }()
1853+
1854+ for _ , tt := range tests {
1855+ actualScanTypes = "sast,sca,kics,scs"
1856+ t .Run (tt .name , func (t * testing.T ) {
1857+ cmdCommand := & cobra.Command {
1858+ Use : "scan" ,
1859+ Short : "Scan a project" ,
1860+ Long : `Scan a project` ,
1861+ }
1862+ cmdCommand .PersistentFlags ().Bool (commonParams .SastFastScanFlag , false , "Fast scan flag" )
1863+ cmdCommand .PersistentFlags ().Bool (commonParams .IncrementalSast , false , "Incremental scan flag" )
1864+
1865+ _ = cmdCommand .Execute ()
1866+
1867+ if tt .requiredFastScanSet {
1868+ _ = cmdCommand .PersistentFlags ().Set (commonParams .SastFastScanFlag , tt .fastScanFlag )
1869+ }
1870+ if tt .requiredIncrementalSet {
1871+ _ = cmdCommand .PersistentFlags ().Set (commonParams .IncrementalSast , tt .incrementalFlag )
1872+ }
1873+
1874+ result := addSastScan (cmdCommand , resubmitConfig )
1875+
1876+ actualSastConfig := wrappers.SastConfig {}
1877+ for key , value := range result {
1878+ if key == resultsMapType {
1879+ assert .Equal (t , commonParams .SastType , value )
1880+ } else if key == resultsMapValue {
1881+ actualSastConfig = * value .(* wrappers.SastConfig )
1882+ }
1883+ }
1884+
1885+ if ! reflect .DeepEqual (actualSastConfig , tt .expectedConfig ) {
1886+ t .Errorf ("Expected %+v, but got %+v" , tt .expectedConfig , actualSastConfig )
1887+ }
1888+ })
1889+ }
1890+ }
1891+
17691892func TestValidateScanTypes (t * testing.T ) {
17701893 tests := []struct {
17711894 name string
0 commit comments