Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw and exception when raise on error is set to false #293

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ def detect(self) -> "Resource":
if found_resources:
self.gcp_resources = found_resources
break
if not self.gcp_resources:
if self.raise_on_error and not self.gcp_resources:
raise NoGoogleResourcesFound()
return Resource(self.gcp_resources)
Original file line number Diff line number Diff line change
Expand Up @@ -526,5 +526,17 @@ def test_resource_finding_fallback(self, getter):
def test_no_resources_found(self, getter):
# If no Google resources were found, we throw an exception
getter.return_value.json.side_effect = Exception
resource_finder = GoogleCloudResourceDetector()

resource_finder = GoogleCloudResourceDetector(raise_on_error=True)

self.assertRaises(NoGoogleResourcesFound, resource_finder.detect)

def test_detector_dont_raise_on_error(self, getter):
# If no Google resources were found, we throw an exception
getter.return_value.json.side_effect = Exception
detector = GoogleCloudResourceDetector(raise_on_error=False)
expected_resources = Resource({})

resources = detector.detect()

self.assertEqual(resources, expected_resources)