Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sonertari committed Aug 29, 2019
1 parent df464c7 commit 240af42
Show file tree
Hide file tree
Showing 5 changed files with 577 additions and 135 deletions.
25 changes: 25 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,28 @@ impl Client {
failed
}
}

#[cfg(test)]
mod tests {
use super::*;
use testend::TestConfig;
use manager::configure_proto;

#[test]
fn test_name() {
let (cli2mgr_tx, _cli2mgr_rx) = mpsc::channel();
let (_mgr2cli_tx, mgr2cli_rx) = mpsc::channel();
let mgr2cli_rx = Arc::new(Mutex::new(mgr2cli_rx));

let mut testconfig = TestConfig { proto: BTreeMap::new(), client: BTreeMap::new(), server: BTreeMap::new() };
let proto = configure_proto(&testconfig);

testconfig.client.insert("ip".to_string(), "".to_string());
testconfig.client.insert("port".to_string(), "".to_string());

let client = Client::new(1, 1, 1, 1, cli2mgr_tx.clone(), Arc::clone(&mgr2cli_rx),
proto.clone(), testconfig.client.clone());

assert_eq!(client.base.name, "CLI.h1.s1.c1.t1");
}
}
15 changes: 15 additions & 0 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,18 @@ fn num2level(level: i32) -> LevelFilter {
_ => panic!("Log level not supported"),
}
}

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

#[test]
fn test_num2level() {
assert_eq!(num2level(0), LevelFilter::Off);
assert_eq!(num2level(1), LevelFilter::Error);
assert_eq!(num2level(2), LevelFilter::Warn);
assert_eq!(num2level(3), LevelFilter::Info);
assert_eq!(num2level(4), LevelFilter::Debug);
assert_eq!(num2level(5), LevelFilter::Trace);
}
}
Loading

0 comments on commit 240af42

Please sign in to comment.