Merge pull request #1074 from matthiasbeyer/libimagentrylink/test-external
libimagentrylink: test external linking
This commit is contained in:
commit
c0f4abc8cb
2 changed files with 42 additions and 2 deletions
|
@ -19,7 +19,6 @@ log = "0.3"
|
||||||
toml = "^0.4"
|
toml = "^0.4"
|
||||||
url = "1.2"
|
url = "1.2"
|
||||||
rust-crypto = "0.2"
|
rust-crypto = "0.2"
|
||||||
env_logger = "0.3"
|
|
||||||
is-match = "0.1"
|
is-match = "0.1"
|
||||||
toml-query = "^0.3.1"
|
toml-query = "^0.3.1"
|
||||||
error-chain = "0.10"
|
error-chain = "0.10"
|
||||||
|
@ -27,3 +26,7 @@ error-chain = "0.10"
|
||||||
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
|
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
|
||||||
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }
|
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
env_logger = "0.4"
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ impl Link for Entry {
|
||||||
|
|
||||||
fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> {
|
fn get_link_uri_from_filelockentry(&self) -> Result<Option<Url>> {
|
||||||
self.get_header()
|
self.get_header()
|
||||||
.read("links.external.url")
|
.read("links.external.content.url")
|
||||||
.chain_err(|| LEK::EntryHeaderReadError)
|
.chain_err(|| LEK::EntryHeaderReadError)
|
||||||
.and_then(|opt| match opt {
|
.and_then(|opt| match opt {
|
||||||
Some(&Value::String(ref s)) => {
|
Some(&Value::String(ref s)) => {
|
||||||
|
@ -160,7 +160,9 @@ pub mod iter {
|
||||||
use super::is_external_link_storeid;
|
use super::is_external_link_storeid;
|
||||||
|
|
||||||
while let Some(elem) = self.0.next() {
|
while let Some(elem) = self.0.next() {
|
||||||
|
trace!("Check whether is external: {:?}", elem);
|
||||||
if !(self.1 ^ is_external_link_storeid(&elem)) {
|
if !(self.1 ^ is_external_link_storeid(&elem)) {
|
||||||
|
trace!("Is external id: {:?}", elem);
|
||||||
return Some(elem);
|
return Some(elem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,6 +272,7 @@ pub mod iter {
|
||||||
debug!("Store::retrieve({:?}) succeeded", id);
|
debug!("Store::retrieve({:?}) succeeded", id);
|
||||||
debug!("getting external link from file now");
|
debug!("getting external link from file now");
|
||||||
f.get_link_uri_from_filelockentry()
|
f.get_link_uri_from_filelockentry()
|
||||||
|
.map_dbg_str("Error happened while getting link URI from FLE")
|
||||||
.map_dbg_err(|e| format!("URL -> Err = {:?}", e))
|
.map_dbg_err(|e| format!("URL -> Err = {:?}", e))
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -414,3 +417,37 @@ impl ExternalLinker for Entry {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use libimagstore::store::Store;
|
||||||
|
|
||||||
|
fn setup_logging() {
|
||||||
|
use env_logger;
|
||||||
|
let _ = env_logger::init().unwrap_or(());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_store() -> Store {
|
||||||
|
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
||||||
|
let backend = Box::new(InMemoryFileAbstraction::new());
|
||||||
|
Store::new_with_backend(PathBuf::from("/"), None, backend).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_simple() {
|
||||||
|
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_external_link(&store, url.clone()).is_ok());
|
||||||
|
|
||||||
|
assert_eq!(1, e.get_external_links(&store).unwrap().count());
|
||||||
|
assert_eq!(url, e.get_external_links(&store).unwrap().next().unwrap().unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue