Skip to content

Commit

Permalink
Update scan snapshot to pass default value of empty list (#337)
Browse files Browse the repository at this point in the history
* Update scan snapshot to pass default value of empty list

* Add unit test to verify if ignore list wildcard correctly ignores all files and folders within

* Update test_file_scanner.py

* fix and update unit tests for file scanner
  • Loading branch information
keithlai124 authored Feb 14, 2025
1 parent 5122844 commit 9b1b615
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/credentialdigger/cli/scan_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def configure_parser(parser):
help='Maximum depth for subdirectories scanning (If it is set to -1 or\
not specified, all subdirectories will be scanned)')
parser.add_argument(
'--ignore_list', default=None, nargs='+',
'--ignore_list', default=[], nargs='+',
help='A list of paths to ignore during the scan')


Expand Down
16 changes: 13 additions & 3 deletions tests/unit_tests/test_file_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,21 @@ def test_prune_depth(self, max_depth, expected_dirs, expected_files):
ignore_list=["subdir_A", "file_b.txt"],
expected_ignored_dirs=["subdir_A"],
expected_ignored_files=["file_b.txt"]),
# Test names with wildcards
# Test wildcard ignores all files that have substring `_A`
param(
ignore_list=["*_a*"],
ignore_list=["*_A*"],
expected_ignored_dirs=[],
expected_ignored_files=["file_a.txt", "scan_a.py"]),
expected_ignored_files=["file_Aa.yml", "file_ABa.txt"]),
# Test wildcard ignores all files that end with `.txt`
param(
ignore_list=["*.txt"],
expected_ignored_dirs=[""],
expected_ignored_files=["scan_b.txt", "file_ABa.txt"]),
# Test wildcard ignores dir and all files within
param(
ignore_list=["*subdir_A*"],
expected_ignored_dirs=["subdir_A", "subdir_AB"],
expected_ignored_files=["file_Aa.yml", "file_ABa.txt"]),
# Test nonexistent files and wildcards
param(
ignore_list=["nonexistent_file.txt", "*z*"],
Expand Down

0 comments on commit 9b1b615

Please sign in to comment.