4 releases (2 breaking)
Uses old Rust 2015
0.3.1 | Jan 1, 2018 |
---|---|
0.3.0 | Jan 1, 2018 |
0.2.0 | Dec 30, 2017 |
0.1.0 | Dec 30, 2017 |
#170 in #monitor
16KB
237 lines
repomon-config
lib.rs
:
Configuration management for repomon.
Examples
Read from TOML string
#
#
#
#
let test_toml = r#"[[branch.blah]]
name = "origin/master"
interval = "1m"
[[branch.repomon]]
name = "origin/master"
interval = "1m"
[[branch.repomon]]
name = "origin/feature/testing"
interval = "1m"
[[branch.repomon-config]]
name = "origin/master"
interval = "1m"
"#;
// Serialize the TOML above into a `Branches` struct.
let mut reader = Cursor::new(test_toml);
let branches = read_toml(&mut reader)?;
// Check the `Branches` struct.
let branch_map = branches.branch_map();
assert_eq!(branch_map.keys().len(), 3);
assert!(branch_map.contains_key("repomon"));
assert!(branch_map.contains_key("repomon-config"));
assert!(branch_map.contains_key("blah"));
// Check we have the right number of branch definitions per repo.
let mut branches = branch_map.get("repomon").ok_or("invalid key")?;
assert_eq!(branches.len(), 2);
branches = branch_map.get("repomon-config").ok_or("invalid key")?;
assert_eq!(branches.len(), 1);
branches = branch_map.get("blah").ok_or("invalid key")?;
assert_eq!(branches.len(), 1);
Write to TOML string
#
#
#
#
#
#
#
#
// Setup the `Branches` struct.
let mut master: Branch = Default::default();
master.set_name("origin/master".to_string());
master.set_interval("1m".to_string());
let mut feature_testing: Branch = Default::default();
feature_testing.set_name("origin/feature/testing".to_string());
feature_testing.set_interval("1m".to_string());
let repomon_branches = vec![master.clone(), feature_testing];
let blah_branches = vec![master.clone()];
let repomon_config_branches = vec![master];
let mut branch_map = BTreeMap::new();
branch_map.insert("repomon".to_string(), repomon_branches);
branch_map.insert("repomon-config".to_string(), repomon_config_branches);
branch_map.insert("blah".to_string(), blah_branches);
let mut branches: Branches = Default::default();
branches.set_branch_map(branch_map);
// Write the TOML to the given buf.
let mut buf = [0; 5000];
// Wrapped to drop mutable borrow.
{
let mut writer = Cursor::new(&mut buf[..]);
write_toml(&branches, &mut writer)?;
}
// Check that the result is the same as the TOML above.
assert_eq!(TEST_TOML, String::from_utf8_lossy(&buf));
Dependencies
~4–10MB
~120K SLoC