Mockall: cannot match expection of tower::Service for mocking aws sdk calls

I am wanting to mock aws sdk calls. The aws sdk clients take a connector that performs the interaction with the aws services. I thought I would mock the connector and then pass in a mocked connector to the aws clients.

I'm using mockall and my mocked connector looks like this:

    type SdkBody = aws_smithy_http::body::SdkBody;
    type ConnectorError = aws_smithy_http::result::ConnectorError;
    type AwsRequestBody = http::Request<SdkBody>;
    type AwsResponseBody = http::Response<SdkBody>;

    mockall::mock! {
        Connector {}
        impl tower::Service<AwsRequestBody> for Connector
        {
            type Error = ConnectorError;
            type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
            type Response = AwsResponseBody;

            fn poll_ready<'c>(
                &mut self,
                cx: &mut std::task::Context<'c>,
            ) -> std::task::Poll<Result<(), <Self as tower::Service<AwsRequestBody>>::Error>>;

            fn call(&mut self, req: AwsRequestBody) -> <Self as tower::Service<AwsRequestBody>>::Future;
        }
        impl Clone for Connector {
            fn clone(&self) -> Self;
        }
    }

I've implemented Clone because it is required by consumers of the connector.

Here is the setup of the mocked connector:

    let mut connector = MockConnector::new();
    connector
        .expect_clone()
        .returning(|| MockConnector::new());
    connector
        .expect_poll_ready()
        .returning(|_| std::task::Poll::Ready(Ok(())));

The expectation on the use of clone works (but I don't care about that), but I can't get a match on calls to poll_ready with the panic:

'MockConnector::poll_ready(?): No matching expectation found'

Questions:

  1. How can I create a correct matching expectation?
  2. Is there a way that I can tell mockall that I do not care about clone and poll_ready and these can always return a constant value? I'm only interested in the sequence of values that call returns (and possibly the values of the arguments it receives).

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.