Skip to content

Commit

Permalink
Don't throw and exception when raise on error is set to false (#293)
Browse files Browse the repository at this point in the history
* don't throw and exception when raise on error is set to false.

* fix no new line at end of gcp resource detector test file

* make the expected resources value for the same as the default resources

* remove uneeded else
  • Loading branch information
Tasty213 authored Nov 2, 2023
1 parent d1358d0 commit 0b37f88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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)

0 comments on commit 0b37f88

Please sign in to comment.