~matthiasbeyer/imag

45d0d2d3bbbb7454a3e88631f951edea72000566 — Matthias Beyer 2 years ago ad3c2c6
Add test whether adding an URL works

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
1 files changed, 41 insertions(+), 0 deletions(-)

M lib/entry/libimagentryurl/src/linker.rs
M lib/entry/libimagentryurl/src/linker.rs => lib/entry/libimagentryurl/src/linker.rs +41 -0
@@ 178,6 178,47 @@ mod tests {
        Store::new_inmemory(PathBuf::from("/"), &None).unwrap()
    }

    #[test]
    fn test_adding_url() {
        use toml_query::read::TomlValueReadTypeExt;

        setup_logging();
        let store = get_store();
        let mut e = store.retrieve(PathBuf::from("base-test_simple")).unwrap();
        let url   = Url::parse("http://google.de").unwrap();

        assert!(e.add_url(&store, url.clone()).is_ok());

        debug!("{:?}", e);
        debug!("Header: {:?}", e.get_header());

        let link = e.links().unwrap().next();
        assert!(link.is_some());
        let link = link.unwrap();

        debug!("link[0] = {:?}", link);
        let id = link.get_store_id();

        let link_entry = store.get(id.clone()).unwrap().unwrap();

        debug!("Entry = {:?}", link_entry);
        debug!("Header = {:?}", link_entry.get_header());

        let link = match link_entry.get_header().read_string("url.uri") {
            Ok(Some(s)) => s,
            Ok(None) => {
                assert!(false);
                unreachable!()
            },
            Err(e) => {
                error!("{:?}", e);
                assert!(false);
                unreachable!()
            },
        };

        assert_eq!(link, "http://google.de/");
    }

    #[test]
    fn test_simple() {