remozipsy 0.2.0

Remote Zip Sync - sync remote zip to local fs
Documentation
//! Default implementations for RemoteZip that are only available with the
//! `reqwest` feature enabled.

mod cached;
mod local;

pub use cached::ReqwestCachedRemoteZip;
pub use local::{ReqwestRemoteZip, ReqwestRemoteZipError};

/// Mocks for unittests
#[cfg(test)]
mod test_utils {
    use mockall::*;
    use std::{
        fmt::Debug,
        future::Future,
        pin::Pin,
        sync::{Arc, Mutex},
        task::{Context, Poll},
    };
    use tower_service::Service;

    #[derive(Clone, Debug)]
    #[allow(dead_code)]
    pub(crate) struct DummyService {}

    mock! {
        pub DummyService {}
        impl Service<reqwest::Request> for DummyService {
            type Error = reqwest::Error;
            type Future = Pin<Box<dyn Future<Output = Result<reqwest::Response, reqwest::Error>> + Send + 'static>>;
            type Response = reqwest::Response;

            fn poll_ready<'a>(&mut self, _cx: &mut Context<'a>) -> Poll<Result<(), reqwest::Error>>;

            fn call(
                &mut self,
                req: reqwest::Request,
            ) -> Pin<Box<dyn Future<Output = Result<reqwest::Response, reqwest::Error>> + Send + 'static>>;
        }
    }

    #[derive(Clone)]
    pub(crate) struct MockService {
        pub(crate) inner: Arc<Mutex<MockDummyService>>,
    }

    impl Service<reqwest::Request> for MockService {
        type Error = reqwest::Error;
        type Future = Pin<Box<dyn Future<Output = Result<reqwest::Response, reqwest::Error>> + Send + 'static>>;
        type Response = reqwest::Response;

        fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), reqwest::Error>> {
            let mut lock = self.inner.lock().unwrap();
            lock.poll_ready(cx)
        }

        fn call(
            &mut self,
            req: reqwest::Request,
        ) -> Pin<Box<dyn Future<Output = Result<reqwest::Response, reqwest::Error>> + Send + 'static>> {
            let mut lock = self.inner.lock().unwrap();
            lock.call(req)
        }
    }
}