Skip to content

Commit 17cbafb

Browse files
CM-55749-Tests coverage
1 parent d2d31cb commit 17cbafb

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

cycode/cli/apps/scan/code_scanner.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ def scan_disk_files(ctx: typer.Context, paths: tuple[str, ...]) -> None:
5656
is_cycodeignore_allowed=is_cycodeignore_allowed_by_scan_config(ctx),
5757
)
5858

59-
# Add entrypoint.cycode file at each root path to mark the scan root
60-
for root_path in paths:
59+
# Add entrypoint.cycode file at root path to mark the scan root (only for single path)
60+
if len(paths) == 1:
61+
root_path = paths[0]
6162
absolute_root_path = get_absolute_path(root_path)
6263
entrypoint_path = get_path_by_os(os.path.join(absolute_root_path, consts.CYCODE_ENTRYPOINT_FILENAME))
6364
entrypoint_document = Document(

tests/cli/commands/scan/test_code_scanner.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
2+
from unittest.mock import MagicMock, Mock, patch
23

34
from cycode.cli import consts
5+
from cycode.cli.apps.scan.code_scanner import scan_disk_files
46
from cycode.cli.files_collector.file_excluder import _is_file_relevant_for_sca_scan
57
from cycode.cli.files_collector.path_documents import _generate_document
68
from cycode.cli.models import Document
@@ -72,3 +74,47 @@ def test_generate_document() -> None:
7274
assert isinstance(generated_tfplan_document, Document)
7375
assert generated_tfplan_document.path.endswith('.tf')
7476
assert generated_tfplan_document.is_git_diff_format == is_git_diff
77+
78+
79+
@patch('cycode.cli.apps.scan.code_scanner.get_relevant_documents')
80+
@patch('cycode.cli.apps.scan.code_scanner.scan_documents')
81+
@patch('cycode.cli.apps.scan.code_scanner.get_scan_parameters')
82+
def test_entrypoint_cycode_added_to_documents(
83+
mock_get_scan_parameters: Mock,
84+
mock_scan_documents: Mock,
85+
mock_get_relevant_documents: Mock,
86+
) -> None:
87+
"""Test that entrypoint.cycode file is added to documents in scan_disk_files."""
88+
# Arrange
89+
mock_ctx = MagicMock()
90+
mock_ctx.obj = {
91+
'scan_type': consts.SAST_SCAN_TYPE,
92+
'progress_bar': MagicMock(),
93+
}
94+
mock_get_scan_parameters.return_value = {}
95+
96+
mock_documents = [
97+
Document('/test/path/file1.py', 'content1', is_git_diff_format=False),
98+
Document('/test/path/file2.js', 'content2', is_git_diff_format=False),
99+
]
100+
mock_get_relevant_documents.return_value = mock_documents.copy()
101+
test_path = '/Users/test/repositories'
102+
103+
# Act
104+
scan_disk_files(mock_ctx, (test_path,))
105+
106+
# Assert
107+
call_args = mock_scan_documents.call_args
108+
documents_passed = call_args[0][1]
109+
110+
# Verify entrypoint document was added
111+
entrypoint_docs = [
112+
doc for doc in documents_passed if doc.path.endswith(consts.CYCODE_ENTRYPOINT_FILENAME)
113+
]
114+
assert len(entrypoint_docs) == 1
115+
116+
entrypoint_doc = entrypoint_docs[0]
117+
assert entrypoint_doc.path == os.path.join(test_path, consts.CYCODE_ENTRYPOINT_FILENAME)
118+
assert entrypoint_doc.content == ''
119+
assert entrypoint_doc.is_git_diff_format is False
120+
assert entrypoint_doc.absolute_path == entrypoint_doc.path

0 commit comments

Comments
 (0)