1+ import re
2+
13import click
24import pytest
35import typer
6+ from typer .testing import CliRunner
47
8+ from cycode .cli .app import app
59from cycode .cli .apps .scan .scan_command import scan_command_result_callback
610from cycode .cli .consts import ISSUE_DETECTED_STATUS_CODE , NO_ISSUES_STATUS_CODE , SCAN_ERROR_STATUS_CODE
711
812
13+ def _strip_ansi (text : str ) -> str :
14+ return re .sub (r'\x1b\[[0-9;]*[mGKHF]' , '' , text )
15+
16+
917def _make_ctx (** obj_overrides : object ) -> click .Context :
1018 obj = {
1119 'soft_fail' : False ,
@@ -25,6 +33,21 @@ def _invoke_result_callback(ctx: click.Context) -> int:
2533 return exc_info .value .exit_code
2634
2735
36+ class TestScanCommand :
37+ def test_multiple_scan_types_rejected (self ) -> None :
38+ result = CliRunner ().invoke (app , ['scan' , '-t' , 'iac' , '-t' , 'sast' , 'path' , '.' ])
39+ assert result .exit_code == 1
40+ output = _strip_ansi (result .output )
41+ assert '-t/--scan-type' in output
42+ assert 'iac' in output
43+ assert 'sast' in output
44+
45+ def test_single_scan_type_accepted (self ) -> None :
46+ result = CliRunner ().invoke (app , ['scan' , '-t' , 'iac' , '--help' ])
47+ assert result .exit_code == 0
48+ assert 'Error' not in result .output
49+
50+
2851class TestScanCommandResultCallback :
2952 def test_no_issues_no_errors_exits_zero (self ) -> None :
3053 assert _invoke_result_callback (_make_ctx ()) == NO_ISSUES_STATUS_CODE
0 commit comments