  def testFindResourceByName(self):
    """Test _findResourceByName handles error cases."""
    test_compute = gcp_mocks.FAKE_SOURCE_PROJECT.compute
    test_resources = {
      gcp_mocks.FAKE_INSTANCE.resource_id: gcp_mocks.FAKE_INSTANCE
    }
    test_resources_dup_name = {
      gcp_mocks.FAKE_INSTANCE.resource_id: gcp_mocks.FAKE_INSTANCE,
      gcp_mocks.FAKE_INSTANCE_NAME_DUP.resource_id: gcp_mocks.FAKE_INSTANCE_NAME_DUP
    }
    # pylint: disable=protected-access
    self.assertEqual(
        test_compute._FindResourceByName(test_resources, 'fake-instance'),
        gcp_mocks.FAKE_INSTANCE)
    self.assertEqual(
        test_compute._FindResourceByName(test_resources_dup_name, 'fake-instance', zone='fake-zone'),
        gcp_mocks.FAKE_INSTANCE)
    with self.assertRaises(errors.ResourceNotFoundError):
      test_compute._FindResourceByName(test_resources, 'not-found')
    with self.assertRaises(errors.AmbiguousIdentifierError):
      test_compute._FindResourceByName(test_resources_dup_name, 'fake-instance')
Test _findResourceByName handles error cases.
tests/providers/gcp/internal/test_compute.py