pub struct ServerManager { /* private fields */ }Expand description
Struct to represent many mock servers running in a background thread
Implementations§
Source§impl ServerManager
impl ServerManager
Sourcepub fn new() -> ServerManager
pub fn new() -> ServerManager
Construct a new ServerManager for scheduling several instances of mock servers on one tokio runtime.
Sourcepub fn spawn_mock_server(
&mut self,
builder: MockServerBuilder,
) -> Result<Either<MockServer, (String, u16)>>
pub fn spawn_mock_server( &mut self, builder: MockServerBuilder, ) -> Result<Either<MockServer, (String, u16)>>
Consumes the mock server builder, and then spawns the resulting mock server on the server manager’s runtime. Note that this function will block the current calling thread.
The returned value depends on whether the mock server is directly managed by this manager or provided by a plugin. For plugin provided mock servers, the function will return the mock server ID and port.
Sourcepub fn spawn_http_mock_server(
&mut self,
builder: MockServerBuilder,
) -> Result<MockServer>
pub fn spawn_http_mock_server( &mut self, builder: MockServerBuilder, ) -> Result<MockServer>
Consumes the mock server builder, and then spawns the resulting HTTP mock server on the server manager’s runtime. Note that this function will block the current calling thread.
This function does not handle mock servers provided by plugins.
Sourcepub fn start_mock_server_with_addr(
&mut self,
id: String,
pact: Box<dyn Pact + Send + Sync>,
addr: SocketAddr,
config: MockServerConfig,
) -> Result<SocketAddr>
👎Deprecated since 2.0.0-beta.0: Use the mock server builder (MockServerBuilder)
pub fn start_mock_server_with_addr( &mut self, id: String, pact: Box<dyn Pact + Send + Sync>, addr: SocketAddr, config: MockServerConfig, ) -> Result<SocketAddr>
Start a new server on the runtime
Sourcepub fn start_tls_mock_server_with_addr(
&mut self,
id: String,
pact: Box<dyn Pact + Send + Sync>,
addr: SocketAddr,
tls_config: &ServerConfig,
config: MockServerConfig,
) -> Result<SocketAddr>
👎Deprecated since 2.0.0-beta.0: Use the mock server builder (MockServerBuilder)
pub fn start_tls_mock_server_with_addr( &mut self, id: String, pact: Box<dyn Pact + Send + Sync>, addr: SocketAddr, tls_config: &ServerConfig, config: MockServerConfig, ) -> Result<SocketAddr>
Start a new TLS server on the runtime
Sourcepub fn start_mock_server(
&mut self,
id: String,
pact: Box<dyn Pact + Send + Sync>,
port: u16,
config: MockServerConfig,
) -> Result<u16>
👎Deprecated since 2.0.0-beta.0: Use the mock server builder (MockServerBuilder)
pub fn start_mock_server( &mut self, id: String, pact: Box<dyn Pact + Send + Sync>, port: u16, config: MockServerConfig, ) -> Result<u16>
Start a new server on the runtime
Sourcepub async fn start_mock_server_nonblocking(
&mut self,
id: String,
pact: Box<dyn Pact + Send + Sync>,
port: u16,
config: MockServerConfig,
) -> Result<u16, String>
👎Deprecated since 2.0.0-beta.0: Use the mock server builder (MockServerBuilder)
pub async fn start_mock_server_nonblocking( &mut self, id: String, pact: Box<dyn Pact + Send + Sync>, port: u16, config: MockServerConfig, ) -> Result<u16, String>
Start a new server on the runtime, returning the bound port the mock server is running on
Sourcepub fn start_tls_mock_server(
&mut self,
id: String,
pact: Box<dyn Pact + Send + Sync>,
port: u16,
tls: &ServerConfig,
config: MockServerConfig,
) -> Result<u16>
👎Deprecated since 2.0.0-beta.0: Use the mock server builder (MockServerBuilder)
pub fn start_tls_mock_server( &mut self, id: String, pact: Box<dyn Pact + Send + Sync>, port: u16, tls: &ServerConfig, config: MockServerConfig, ) -> Result<u16>
Start a new TLS server on the runtime
Sourcepub fn start_mock_server_for_transport(
&mut self,
id: String,
pact: Box<dyn Pact + Send + Sync>,
addr: SocketAddr,
transport: &CatalogueEntry,
config: MockServerConfig,
) -> Result<SocketAddr>
👎Deprecated since 2.0.0-beta.0: Use the mock server builder (MockServerBuilder)
pub fn start_mock_server_for_transport( &mut self, id: String, pact: Box<dyn Pact + Send + Sync>, addr: SocketAddr, transport: &CatalogueEntry, config: MockServerConfig, ) -> Result<SocketAddr>
Start a new mock server for the provided transport on the runtime. Returns the socket address that the server is running on.
Sourcepub fn shutdown_mock_server_by_id<S: Into<String>>(&mut self, id: S) -> bool
pub fn shutdown_mock_server_by_id<S: Into<String>>(&mut self, id: S) -> bool
Shut down a server by its id. This function will only shut down a local mock server, not one provided by a plugin.
Sourcepub fn shutdown_mock_server_by_port(&mut self, port: u16) -> bool
pub fn shutdown_mock_server_by_port(&mut self, port: u16) -> bool
Shut down a server by its local port number
Sourcepub fn find_mock_server_by_id<R>(
&self,
id: &str,
f: &dyn Fn(&ServerManager, Either<&MockServer, &PluginMockServer>) -> R,
) -> Option<R>
pub fn find_mock_server_by_id<R>( &self, id: &str, f: &dyn Fn(&ServerManager, Either<&MockServer, &PluginMockServer>) -> R, ) -> Option<R>
Find mock server by id, and map it using supplied function if found.
Sourcepub fn find_mock_server_by_port<R>(
&mut self,
port: u16,
f: &dyn Fn(&ServerManager, &String, Either<&MockServer, &PluginMockServer>) -> R,
) -> Option<R>
pub fn find_mock_server_by_port<R>( &mut self, port: u16, f: &dyn Fn(&ServerManager, &String, Either<&MockServer, &PluginMockServer>) -> R, ) -> Option<R>
Find a mock server by port number and map it using supplied function if found.
Sourcepub fn find_mock_server_by_port_mut<R>(
&mut self,
port: u16,
f: &dyn Fn(&mut MockServer) -> R,
) -> Option<R>
pub fn find_mock_server_by_port_mut<R>( &mut self, port: u16, f: &dyn Fn(&mut MockServer) -> R, ) -> Option<R>
Find a mock server by port number and apply a mutating operation on it if successful. This will only work for locally managed mock servers, not mock servers provided by plugins.
Sourcepub fn map_mock_servers<R, F>(&self, f: F) -> Vec<R>where
F: Fn(&MockServer) -> R,
pub fn map_mock_servers<R, F>(&self, f: F) -> Vec<R>where
F: Fn(&MockServer) -> R,
Map all the running mock servers This will only work for locally managed mock servers, not mock servers provided by plugins.
Sourcepub fn store_mock_server_resource(&mut self, port: u16, s: CString) -> bool
pub fn store_mock_server_resource(&mut self, port: u16, s: CString) -> bool
Store a string that needs to be cleaned up when the mock server terminates
Sourcepub fn mock_server_matched(&self, id: &str) -> Option<bool>
pub fn mock_server_matched(&self, id: &str) -> Option<bool>
Determines if the mock server running with the given ID has matched all its requests
correctly. If there is no mock server running with that ID, it will return None.
In the case the mock server has not received any requests, it will return Some(true)
as this is the default state.
Sourcepub fn mock_server_matched_by_port(&self, port: u16) -> Option<bool>
pub fn mock_server_matched_by_port(&self, port: u16) -> Option<bool>
Determines if the mock server running on the given port has matched all its requests
correctly. If there is no mock server running on that port, it will return None.
In the case the mock server has not received any requests, it will return Some(true)
as this is the default state.
Sourcepub fn mock_server_mismatches(&self, id: &str) -> Result<Option<Vec<Value>>>
pub fn mock_server_mismatches(&self, id: &str) -> Result<Option<Vec<Value>>>
Returns all the mismatches from the mock server with the given ID. If there is no
mock server with that ID, it will return None. The mismatch values are returned
as JSON. This is to support mock servers provided by plugins, which can have a different
format.
Sourcepub fn mock_server_mismatches_by_port(
&self,
port: u16,
) -> Result<Option<Vec<Value>>>
pub fn mock_server_mismatches_by_port( &self, port: u16, ) -> Result<Option<Vec<Value>>>
Returns all the mismatches from the mock server running on the given port. If there is no
mock server running on that port, it will return None. The mismatch values are returned
as JSON. This is to support mock servers provided by plugins, which can have a different
format.
Auto Trait Implementations§
impl !Freeze for ServerManager
impl !RefUnwindSafe for ServerManager
impl Send for ServerManager
impl !Sync for ServerManager
impl Unpin for ServerManager
impl !UnwindSafe for ServerManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);