  def testGetInstancesByName(self, mock_list_instances):
    """Test that an instance of an account can be found by its name."""
    mock_list_instances.return_value = aws_mocks.MOCK_LIST_INSTANCES
    found_instances = aws_mocks.FAKE_AWS_ACCOUNT.ec2.GetInstancesByName(
        aws_mocks.FAKE_INSTANCE_WITH_NAME.name)
    self.assertEqual(1, len(found_instances))
    self.assertIsInstance(found_instances[0], ec2.AWSInstance)
    self.assertEqual(
        'fake-instance-with-name-id', found_instances[0].instance_id)
    self.assertEqual('fake-zone-2', found_instances[0].region)
    self.assertEqual('fake-zone-2b', found_instances[0].availability_zone)

    found_instances = aws_mocks.FAKE_AWS_ACCOUNT.ec2.GetInstancesByName(
        'non-existent-instance-name')
    self.assertEqual(0, len(found_instances))
Test that an instance of an account can be found by its name.
tests/providers/aws/internal/test_ec2.py