Crate repomon_config [] [src]

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));

Structs

Branch

A branch to monitor for changes.

Branches

A map of repo name to branch definitions.

Error

The Error type.

Message

Struct sent via tx to clients;

Enums

ErrorKind

The kind of an error.

Functions

read_toml

Read TOML from the given reader and deserialize into a Branches struct.

write_toml

Write TOML serialized from the Branches struct to the given writer.