1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! Toxiproxy-Rust is a [Toxiproxy] client written for the Rust language.
//! It's designed for testing network code and its resiliency against various
//! network issues, such as latency or unavailability (and many more).
//!
//! ## Setting up a test
//!
//! ```rust
//! use toxiproxy_rust::{TOXIPROXY, proxy::ProxyPack};
//!
//! TOXIPROXY.populate(vec![ProxyPack::new(
//!     "socket".into(),
//!     "localhost:2001".into(),
//!     "localhost:2000".into(),
//! )]);
//!
//! TOXIPROXY
//!     .find_and_reset_proxy("socket")
//!     .unwrap()
//!     .with_down(|| {
//!         /* For example:
//!         let result = MyService::Server.call();
//!         assert!(result.is_ok());
//!         */
//!     });
//! ```
//!
//! ## Setting up a more advanced test
//!
//! ```rust
//! use toxiproxy_rust::{TOXIPROXY, proxy::ProxyPack};
//!
//! TOXIPROXY.populate(vec![ProxyPack::new(
//!     "socket".into(),
//!     "localhost:2001".into(),
//!     "localhost:2000".into(),
//! )]);
//!
//! TOXIPROXY
//!     .find_and_reset_proxy("socket")
//!     .unwrap()
//!     .with_slicer("downstream".into(), 2048, 128, 0, 0.8)
//!     .with_bandwidth("downstream".into(), 32, 0.5)
//!     .apply(|| {
//!         /* For example:
//!         let result = MyService::Server.call();
//!         assert!(result.is_ok());
//!         */
//!     });
//! ```
//!
//! [Toxiproxy]: https://github.com/Shopify/toxiproxy

#[macro_use]
extern crate lazy_static;

pub mod client;
mod consts;
mod http_client;
pub mod proxy;
pub mod toxic;

use client::*;

lazy_static! {
    /// Pre-built client using the default connection address.
    pub static ref TOXIPROXY: Client = Client::new("127.0.0.1:8474");
}