@@ -63,7 +63,7 @@ const (
6363 SCSScoreCardError = "SCS scan failed to start: Scorecard scan is missing required flags, please include in the ast-cli arguments: " +
6464 "--scs-repo-url your_repo_url --scs-repo-token your_repo_token"
6565 outputFileName = "test_output.log"
66- noUpdatesForExistingProject = "No tags to update. Skipping project update."
66+ noUpdatesForExistingProject = "No tags or branch to update. Skipping project update."
6767 ScaResolverZipNotSupportedErr = "Scanning Zip files is not supported by ScaResolver.Please use non-zip source"
6868)
6969
@@ -400,6 +400,7 @@ func TestCreateScanBranches(t *testing.T) {
400400 // Bind cx_branch environment variable
401401 _ = viper .BindEnv ("cx_branch" , "CX_BRANCH" )
402402 viper .SetDefault ("cx_branch" , "branch_from_environment_variable" )
403+ assert .Equal (t , viper .GetString ("cx_branch" ), "branch_from_environment_variable" )
403404
404405 // Test branch from environment variable. Since the cx_branch is bind the scan must run successfully without a branch flag defined
405406 execCmdNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo )
@@ -637,6 +638,35 @@ func TestCreateScanResubmitWithScanTypes(t *testing.T) {
637638 execCmdNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--scan-types" , "sast,iac-security,sca" , "--debug" , "--resubmit" )
638639}
639640
641+ func TestCreateScanWithPrimaryBranchFlag_Passed (t * testing.T ) {
642+ execCmdNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--debug" , "--branch-primary" )
643+ }
644+
645+ func TestCreateScanWithPrimaryBranchFlagBooleanValueTrue_Failed (t * testing.T ) {
646+ original := os .Args
647+ defer func () { os .Args = original }()
648+ os .Args = []string {
649+ "scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--debug" , "--branch-primary=true" ,
650+ }
651+ err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--debug" , "--branch-primary=true" )
652+ assert .ErrorContains (t , err , "invalid value for --branch-primary flag" , err .Error ())
653+ }
654+
655+ func TestCreateScanWithPrimaryBranchFlagBooleanValueFalse_Failed (t * testing.T ) {
656+ original := os .Args
657+ defer func () { os .Args = original }()
658+ os .Args = []string {
659+ "scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--debug" , "--branch-primary=false" ,
660+ }
661+ err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--debug" , "--branch-primary=false" )
662+ assert .ErrorContains (t , err , "invalid value for --branch-primary flag" , err .Error ())
663+ }
664+
665+ func TestCreateScanWithPrimaryBranchFlagStringValue_Should_Fail (t * testing.T ) {
666+ err := execCmdNotNilAssertion (t , "scan" , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" , "--debug" , "--branch-primary=string" )
667+ assert .ErrorContains (t , err , "invalid argument \" string\" " , err .Error ())
668+ }
669+
640670func Test_parseThresholdSuccess (t * testing.T ) {
641671 want := make (map [string ]int )
642672 want ["iac-security-low" ] = 1
@@ -645,7 +675,6 @@ func Test_parseThresholdSuccess(t *testing.T) {
645675 t .Errorf ("parseThreshold() = %v, want %v" , got , want )
646676 }
647677}
648-
649678func Test_parseThresholdsSuccess (t * testing.T ) {
650679 want := make (map [string ]int )
651680 want ["sast-high" ] = 1
@@ -656,15 +685,13 @@ func Test_parseThresholdsSuccess(t *testing.T) {
656685 t .Errorf ("parseThreshold() = %v, want %v" , got , want )
657686 }
658687}
659-
660688func Test_parseThresholdParseError (t * testing.T ) {
661689 want := make (map [string ]int )
662690 threshold := " KICS - LoW=error"
663691 if got := parseThreshold (threshold ); ! reflect .DeepEqual (got , want ) {
664692 t .Errorf ("parseThreshold() = %v, want %v" , got , want )
665693 }
666694}
667-
668695func TestCreateScanProjectTags (t * testing.T ) {
669696 execCmdNilAssertion (t , scanCommand , "create" , "--project-name" , "MOCK" , "-s" , dummyRepo , "-b" , "dummy_branch" ,
670697 "--project-tags" , "test" , "--debug" )
0 commit comments