StatsDServer

Struct StatsDServer 

Source
pub struct StatsDServer { /* private fields */ }

Implementations§

Source§

impl StatsDServer

Source

pub fn new() -> Self

Source

pub fn addr(&self) -> String

Return the mock server address: 127.0.0.1:<random port>

Source

pub fn run_while_receiving_all<F>(self, func: F) -> Vec<String>
where F: Fn(),

Run the given test function while receiving several packets. Return a vector of the packets.

use statsd::Client;

// Start the mock server
let mock = statsd_mock::start();

let client = Client::new(&mock.addr(), "duyet").unwrap();
let response = mock.run_while_receiving_all(|| {
    client.incr("some.counter");
    client.count("some.counter", 123.0);
});
assert_eq!(
    response,
    vec!["duyet.some.counter:1|c", "duyet.some.counter:123|c"]
);
Source

pub fn capture_all<F>(self, func: F) -> Vec<String>
where F: Fn(),

Run the given test function while receiving several packets. Return a vector of the packets.

Source

pub fn run_while_receiving<F>(self, func: F) -> String
where F: Fn(),

Run the given test function while receiving several packets. Return the concatenation of the packets.

use statsd::Client;

// Start the mock server
let mock = statsd_mock::start();

let client = Client::new(&mock.addr(), "duyet").unwrap();
let response = mock.run_while_receiving(|| {
    client.count("some.counter", 123.0);
});
assert_eq!(response, "duyet.some.counter:123|c");
Source

pub fn capture<F>(self, func: F) -> String
where F: Fn(),

Run the given test function while receiving several packets. Return the concatenation of the packets.

Trait Implementations§

Source§

impl Default for StatsDServer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.