~matthiasbeyer/imag

ae9fbe866f8dec1de33b2329aeba30c84415aeae — Matthias Beyer 2 years ago c5519da
Add test whether setting tags works

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
M lib/entry/libimagentrytag/Cargo.toml => lib/entry/libimagentrytag/Cargo.toml +3 -0
@@ 42,3 42,6 @@ version = "^2.29"
default-features = false
features = ["color", "suggestions", "wrap_help"]

[dev-dependencies]
env_logger = "0.5"


M lib/entry/libimagentrytag/src/lib.rs => lib/entry/libimagentrytag/src/lib.rs +2 -0
@@ 48,6 48,8 @@ extern crate serde;
extern crate filters;
#[macro_use] extern crate failure;

#[cfg(test)] extern crate env_logger;

extern crate libimagstore;
extern crate libimagerror;


M lib/entry/libimagentrytag/src/tagable.rs => lib/entry/libimagentrytag/src/tagable.rs +40 -0
@@ 116,3 116,43 @@ impl Tagable for Entry {

}

#[cfg(test)]
mod tests {
    use std::path::PathBuf;

    use toml_query::read::TomlValueReadTypeExt;

    use libimagstore::store::Store;

    use super::*;

    fn setup_logging() {
        let _ = ::env_logger::try_init();
    }

    fn get_store() -> Store {
        Store::new_inmemory(PathBuf::from("/"), &None).unwrap()
    }

    #[test]
    fn test_tag_set_sets_tag() {
        setup_logging();
        let store = get_store();
        let name = "test-tag-set-sets-tags";

        debug!("Creating default entry");
        let id = PathBuf::from(String::from(name));
        let mut entry = store.create(id).unwrap();

        let tags = vec![String::from("testtag")];
        entry.set_tags(&tags).unwrap();

        let v = entry.get_header().read_string("tags.values.[0]").unwrap();

        assert!(v.is_some());
        let v = v.unwrap();

        assert_eq!(v, "testtag");
    }

}