Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
add a mock the aggregator rpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
little-dude committed Mar 26, 2020
1 parent 30ebca6 commit 406ba68
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 1 deletion.
96 changes: 96 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ opentelemetry = { version = "0.2.0", optional = true }
tracing-opentelemetry = { version = "0.2.0", optional = true }
opentelemetry-jaeger = { version = "0.1.0", optional = true }

[dev-dependencies]
mockall = "0.6.0"

[[bin]]
name = "coordinator"
path = "src/bin/coordinator.rs"
Expand Down
37 changes: 36 additions & 1 deletion rust/src/aggregator/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,42 @@ mod inner {
}
}

pub use inner::{Rpc, RpcClient as Client};
pub use inner::Rpc;

#[cfg(test)]
mod mocks {
pub use super::*;

use futures::future;
use mockall::mock;
use std::io;
use tarpc::{client::Config, context::Context, rpc::Transport};

mock! {
pub NewClient {
fn spawn(self) -> io::Result<MockRpcClient>;
}
}

mock! {
pub RpcClient {
fn new<T: Transport<(), ()> + 'static>(config: Config, transport: T) -> MockNewClient;
fn select(&mut self, ctx: Context, credentials: Credentials) -> future::Ready<io::Result<Result<(), ()>>>;
fn aggregate(&mut self, ctx: Context) -> future::Ready<io::Result<Result<(), ()>>>;
}
}

impl Clone for MockRpcClient {
fn clone(&self) -> Self {
Self::default()
}
}
}

#[cfg(not(test))]
pub use inner::RpcClient as Client;
#[cfg(test)]
pub use mocks::MockRpcClient as Client;

/// A server that serves a single client. A new `Server` is created
/// for each new client.
Expand Down

0 comments on commit 406ba68

Please sign in to comment.