update test code
This commit is contained in:
parent
aeb1cbcdd4
commit
f781ca86d0
@ -28,13 +28,13 @@ travis-ci = { repository = "peachcloud/peach-stats", branch = "master" }
|
|||||||
maintenance = { status = "actively-developed" }
|
maintenance = { status = "actively-developed" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.6"
|
env_logger = "0.9"
|
||||||
jsonrpc-core = "11"
|
jsonrpc-core = "18"
|
||||||
jsonrpc-http-server = "11"
|
jsonrpc-http-server = "18"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
miniserde = "0.1.15"
|
miniserde = "0.1.15"
|
||||||
probes = "0.4.1"
|
probes = "0.4.1"
|
||||||
systemstat = "0.1.10"
|
systemstat = "0.1.10"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
jsonrpc-test = "11"
|
jsonrpc-test = "18"
|
||||||
|
@ -16,44 +16,46 @@ pub fn run() -> Result<(), StatError> {
|
|||||||
info!("Creating JSON-RPC I/O handler.");
|
info!("Creating JSON-RPC I/O handler.");
|
||||||
let mut io = IoHandler::default();
|
let mut io = IoHandler::default();
|
||||||
|
|
||||||
io.add_method("cpu_stats", move |_| {
|
io.add_method("cpu_stats", move |_| async {
|
||||||
info!("Fetching CPU statistics.");
|
info!("Fetching CPU statistics.");
|
||||||
let stats = stats::cpu_stats()?;
|
let stats = stats::cpu_stats()?;
|
||||||
|
|
||||||
Ok(Value::String(stats))
|
Ok(Value::String(stats))
|
||||||
});
|
});
|
||||||
|
|
||||||
io.add_method("cpu_stats_percent", move |_| {
|
io.add_method("cpu_stats_percent", move |_| async {
|
||||||
info!("Fetching CPU statistics as percentages.");
|
info!("Fetching CPU statistics as percentages.");
|
||||||
let stats = stats::cpu_stats_percent()?;
|
let stats = stats::cpu_stats_percent()?;
|
||||||
|
|
||||||
Ok(Value::String(stats))
|
Ok(Value::String(stats))
|
||||||
});
|
});
|
||||||
|
|
||||||
io.add_method("disk_usage", move |_| {
|
io.add_method("disk_usage", move |_| async {
|
||||||
info!("Fetching disk usage statistics.");
|
info!("Fetching disk usage statistics.");
|
||||||
let disks = stats::disk_usage()?;
|
let disks = stats::disk_usage()?;
|
||||||
|
|
||||||
Ok(Value::String(disks))
|
Ok(Value::String(disks))
|
||||||
});
|
});
|
||||||
|
|
||||||
io.add_method("load_average", move |_| {
|
io.add_method("load_average", move |_| async {
|
||||||
info!("Fetching system load average statistics.");
|
info!("Fetching system load average statistics.");
|
||||||
let avg = stats::load_average()?;
|
let avg = stats::load_average()?;
|
||||||
|
|
||||||
Ok(Value::String(avg))
|
Ok(Value::String(avg))
|
||||||
});
|
});
|
||||||
|
|
||||||
io.add_method("mem_stats", move |_| {
|
io.add_method("mem_stats", move |_| async {
|
||||||
info!("Fetching current memory statistics.");
|
info!("Fetching current memory statistics.");
|
||||||
let mem = stats::mem_stats()?;
|
let mem = stats::mem_stats()?;
|
||||||
|
|
||||||
Ok(Value::String(mem))
|
Ok(Value::String(mem))
|
||||||
});
|
});
|
||||||
|
|
||||||
io.add_method("ping", |_| Ok(Value::String("success".to_string())));
|
io.add_method("ping", |_| async {
|
||||||
|
Ok(Value::String("success".to_string()))
|
||||||
|
});
|
||||||
|
|
||||||
io.add_method("uptime", move |_| {
|
io.add_method("uptime", move |_| async {
|
||||||
info!("Fetching system uptime.");
|
info!("Fetching system uptime.");
|
||||||
let uptime = stats::uptime()?;
|
let uptime = stats::uptime()?;
|
||||||
|
|
||||||
@ -83,17 +85,17 @@ pub fn run() -> Result<(), StatError> {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use jsonrpc_test as test;
|
use jsonrpc_test as test_rpc;
|
||||||
|
|
||||||
// test to ensure correct success response
|
// test to ensure correct success response
|
||||||
#[test]
|
#[test]
|
||||||
fn rpc_success() {
|
fn rpc_success() {
|
||||||
let rpc = {
|
let rpc = {
|
||||||
let mut io = IoHandler::new();
|
let mut io = IoHandler::new();
|
||||||
io.add_method("rpc_success_response", |_| {
|
io.add_method("rpc_success_response", |_| async {
|
||||||
Ok(Value::String("success".into()))
|
Ok(Value::String("success".into()))
|
||||||
});
|
});
|
||||||
test::Rpc::from(io)
|
test_rpc::Rpc::from(io)
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(rpc.request("rpc_success_response", &()), r#""success""#);
|
assert_eq!(rpc.request("rpc_success_response", &()), r#""success""#);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user