Skip to content

Commit

Permalink
Add unit test for print
Browse files Browse the repository at this point in the history
  • Loading branch information
cadosecurity committed Dec 4, 2023
1 parent a8aebf5 commit 136900c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cloudgrep/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def search_file(
with open(os.path.join(tempdir, filename)) as f:
for line in f:
if self.search_line(
"{key_name}/{filename}",
f"{key_name}/{filename}",
search,
hide_filenames,
line,
Expand Down
9 changes: 9 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ def test_zip(self) -> None:
found = Search().search_file(f"{BASE_PATH}/data/000000.zip", "000000.zip", "Running on machine", False, None)
self.assertTrue(found)

def test_print_match(self) -> None:
# Test output of print_match function

with patch("sys.stdout", new=StringIO()) as fake_out:
Search().search_file(f"{BASE_PATH}/data/000000.zip", "000000.zip", "Running on machine", False, None)
output = fake_out.getvalue().strip()

self.assertIn("Running on machine", output)

@timeout_decorator.timeout(5) # Normally takes around 3 seconds to run in github actions
@mock_s3
def test_e2e(self) -> None:
Expand Down

0 comments on commit 136900c

Please sign in to comment.