|
1 | 1 | import os |
| 2 | +from unittest.mock import MagicMock, Mock, patch |
2 | 3 |
|
3 | 4 | from cycode.cli import consts |
| 5 | +from cycode.cli.apps.scan.code_scanner import scan_disk_files |
4 | 6 | from cycode.cli.files_collector.file_excluder import _is_file_relevant_for_sca_scan |
5 | 7 | from cycode.cli.files_collector.path_documents import _generate_document |
6 | 8 | from cycode.cli.models import Document |
@@ -72,3 +74,47 @@ def test_generate_document() -> None: |
72 | 74 | assert isinstance(generated_tfplan_document, Document) |
73 | 75 | assert generated_tfplan_document.path.endswith('.tf') |
74 | 76 | 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