  def testGetInstancesByNameOrId(self, mock_list_instances):
    """Test that an instance of an account can be found by its name or ID."""
    mock_list_instances.return_value = aws_mocks.MOCK_LIST_INSTANCES
    found_instances = aws_mocks.FAKE_AWS_ACCOUNT.ec2.GetInstancesByNameOrId(
        instance_id=aws_mocks.FAKE_INSTANCE.instance_id)
    self.assertEqual(1, len(found_instances))
    self.assertEqual('fake-instance-id', found_instances[0].instance_id)

    found_instances = aws_mocks.FAKE_AWS_ACCOUNT.ec2.GetInstancesByNameOrId(
        instance_name=aws_mocks.FAKE_INSTANCE_WITH_NAME.name)
    self.assertEqual(1, len(found_instances))
    self.assertEqual(
        'fake-instance-with-name-id', found_instances[0].instance_id)

    with self.assertRaises(ValueError):
      aws_mocks.FAKE_AWS_ACCOUNT.ec2.GetInstancesByNameOrId()

    with self.assertRaises(ValueError):
      aws_mocks.FAKE_AWS_ACCOUNT.ec2.GetInstancesByNameOrId(
          instance_id=aws_mocks.FAKE_INSTANCE.instance_id,
          instance_name=aws_mocks.FAKE_INSTANCE_WITH_NAME.name)
Test that an instance of an account can be found by its name or ID.
tests/providers/aws/internal/test_ec2.py