@@ -193,8 +193,9 @@ func TestScanCreate_ApplicationNameIsNotExactMatch_FailedToCreateScan(t *testing
193193 assert .Assert (t , err .Error () == errorConstants .ApplicationDoesntExistOrNoPermission )
194194}
195195
196- func TestScanCreate_ExistingProjectAndApplicationWithNoPermission_ShouldCreateScan (t * testing.T ) {
197- execCmdNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "--application-name" , mock .ApplicationDoesntExist , "-s" , dummyRepo , "-b" , "dummy_branch" )
196+ func TestScanCreate_ExistingProjectAndApplicationWithNoPermission_ShouldFailScan (t * testing.T ) {
197+ err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "--application-name" , mock .NoPermissionApp , "-s" , dummyRepo , "-b" , "dummy_branch" )
198+ assert .Assert (t , strings .Contains (err .Error (), errorConstants .FailedToGetApplication ), err .Error ())
198199}
199200
200201func TestScanCreate_ExistingApplicationWithNoPermission_FailedToCreateScan (t * testing.T ) {
@@ -712,18 +713,13 @@ func TestCreateScan_WhenProjectExists_ShouldIgnoreGroups(t *testing.T) {
712713 assert .Equal (t , strings .Contains (stdoutString , noUpdatesForExistingProject ), true , "Expected output: %s" , noUpdatesForExistingProject )
713714}
714715
715- func TestCreateScan_WhenProjectExists_ShouldIgnoreApplication (t * testing.T ) {
716- file := createOutputFile (t , outputFileName )
717- defer deleteOutputFile (file )
718- defer logger .SetOutput (os .Stdout )
716+ // Now as we give the ability to assign existing projects to applications , there is validation if application exists
717+
718+ func TestCreateScan_WhenProjectExists_GetApplication_Fails500Err_Failed (t * testing.T ) {
719719 baseArgs := []string {scanCommand , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" ,
720- "--debug" , "--application-name" , "anyApplication" }
721- execCmdNilAssertion (t , baseArgs ... )
722- stdoutString , err := util .ReadFileAsString (file .Name ())
723- if err != nil {
724- t .Fatalf ("Failed to read log file: %v" , err )
725- }
726- assert .Equal (t , strings .Contains (stdoutString , noUpdatesForExistingProject ), true , "Expected output: %s" , noUpdatesForExistingProject )
720+ "--debug" , "--application-name" , mock .FakeInternalServerError500 }
721+ err := execCmdNotNilAssertion (t , baseArgs ... )
722+ assert .ErrorContains (t , err , errorConstants .FailedToGetApplication , err .Error ())
727723}
728724func TestScanCreateLastSastScanTimeWithInvalidValue (t * testing.T ) {
729725 baseArgs := []string {"scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--sca-exploitable-path" , "true" , "--sca-last-sast-scan-time" , "notaniteger" }
@@ -3623,3 +3619,64 @@ func Test_CreateScanWithIgnorePolicyFlag(t *testing.T) {
36233619 "scan" , "create" , "--project-name" , "MOCK" , "-s" , "data/sources.zip" , "--branch" , "dummy_branch" , "--ignore-policy" ,
36243620 )
36253621}
3622+
3623+ func Test_CreateScanWithExistingProjectAndAssign_Application (t * testing.T ) {
3624+ file := createOutputFile (t , outputFileName )
3625+ defer deleteOutputFile (file )
3626+ defer logger .SetOutput (os .Stdout )
3627+
3628+ baseArgs := []string {"scan" , "create" , "--project-name" , "MOCK" , "-s" , "." , "--branch" , "main" , "--application-name" , mock .ExistingApplication , "--debug" }
3629+ execCmdNilAssertion (
3630+ t ,
3631+ baseArgs ... ,
3632+ )
3633+ stdoutString , err := util .ReadFileAsString (file .Name ())
3634+ if err != nil {
3635+ t .Fatalf ("Failed to read log file: %v" , err )
3636+ }
3637+ assert .Equal (t , strings .Contains (stdoutString , "Successfully updated the application" ), true , "Expected output: %s" , "Successfully updated the application" )
3638+ }
3639+
3640+ func Test_CreateScanWithExistingProjectAndAssign_FailedNoApplication_NameProvided (t * testing.T ) {
3641+ file := createOutputFile (t , outputFileName )
3642+ defer deleteOutputFile (file )
3643+ defer logger .SetOutput (os .Stdout )
3644+
3645+ baseArgs := []string {"scan" , "create" , "--project-name" , "MOCK" , "-s" , "." , "--branch" , "main" , "--debug" }
3646+ execCmdNilAssertion (
3647+ t ,
3648+ baseArgs ... ,
3649+ )
3650+ stdoutString , err := util .ReadFileAsString (file .Name ())
3651+ if err != nil {
3652+ t .Fatalf ("Failed to read log file: %v" , err )
3653+ }
3654+ assert .Equal (t , strings .Contains (stdoutString , "No application name provided. Skipping application update" ), true , "Expected output: %s" , "No application name provided. Skipping application update" )
3655+ }
3656+
3657+ func Test_CreateScanWithExistingProjectAndAssign_FailedApplication_DoesNot_Exist (t * testing.T ) {
3658+ baseArgs := []string {"scan" , "create" , "--project-name" , "MOCK" , "-s" , "." , "--branch" , "main" , "--debug" , "--application-name" , "NoPermissionApp" }
3659+ err := execCmdNotNilAssertion (
3660+ t ,
3661+ baseArgs ... ,
3662+ )
3663+ assert .ErrorContains (t , err , errorConstants .FailedToGetApplication , err .Error ())
3664+ }
3665+
3666+ func Test_CreateScanWithExistingProjectAssign_to_Application_FF_DirectAssociationEnabledShouldPass (t * testing.T ) {
3667+ file := createOutputFile (t , outputFileName )
3668+ defer deleteOutputFile (file )
3669+ defer logger .SetOutput (os .Stdout )
3670+
3671+ mock .Flag = wrappers.FeatureFlagResponseModel {Name : wrappers .DirectAssociationEnabled , Status : true }
3672+ baseArgs := []string {"scan" , "create" , "--project-name" , "MOCK" , "-s" , "." , "--branch" , "main" , "--debug" , "--application-name" , mock .ExistingApplication }
3673+ execCmdNilAssertion (
3674+ t ,
3675+ baseArgs ... ,
3676+ )
3677+ stdoutString , err := util .ReadFileAsString (file .Name ())
3678+ if err != nil {
3679+ t .Fatalf ("Failed to read log file: %v" , err )
3680+ }
3681+ assert .Equal (t , strings .Contains (stdoutString , "Successfully updated the application" ), true , "Expected output: %s" , "Successfully updated the application" )
3682+ }
0 commit comments