refactored tests

pull/11/head
Dustin Whitney 5 years ago
parent 5d8e63376b
commit 2aa9114deb
  1. 2
      lib/src/lib.rs
  2. 2
      lib/src/store/mod.rs
  3. 49
      lib/tests/service_test_cases.rs

@ -44,7 +44,7 @@ pub use failure::Error;
pub type Result<T> = ::std::result::Result<T, failure::Error>; pub type Result<T> = ::std::result::Result<T, failure::Error>;
pub use crate::repository::Repository; pub use crate::repository::Repository;
pub use crate::repository::RepositoryConnection; pub use crate::repository::RepositoryConnection;
pub use crate::store::{MemoryRepository, MemoryRepositoryConnection}; pub use crate::store::MemoryRepository;
#[cfg(feature = "rocksdb")] #[cfg(feature = "rocksdb")]
pub use crate::store::RocksDbRepository; pub use crate::store::RocksDbRepository;
pub use crate::syntax::DatasetSyntax; pub use crate::syntax::DatasetSyntax;

@ -6,7 +6,7 @@ pub(crate) mod numeric_encoder;
mod rocksdb; mod rocksdb;
pub use crate::sparql::GraphPattern; pub use crate::sparql::GraphPattern;
pub use crate::store::memory::{MemoryRepository, MemoryRepositoryConnection}; pub use crate::store::memory::MemoryRepository;
#[cfg(feature = "rocksdb")] #[cfg(feature = "rocksdb")]
pub use crate::store::rocksdb::RocksDbRepository; pub use crate::store::rocksdb::RocksDbRepository;

@ -104,6 +104,55 @@ fn two_service_test() {
assert_eq!(collected, solution); assert_eq!(collected, solution);
} }
#[test]
fn silent_service_test() {
#[derive(Clone,Copy)]
struct TwoServiceTest;
impl ServiceHandler for TwoServiceTest {
fn handle<'a>(&'a self, named_node: NamedNode) -> Option<(fn(GraphPattern) -> Result<BindingsIterator<'a>>)> {
Some(TwoServiceTest::handle_service)
}
}
impl TwoServiceTest {
fn handle_service<'a>(_graph_pattern: GraphPattern) -> Result<BindingsIterator<'a>> {
Err(format_err!("This is supposed to fail"))
}
}
let query = r#"
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE
{
SERVICE <http://service1.org>
{ ?s foaf:name ?name
}
SERVICE <http://service2.org>
{ ?s foaf:mbox ?mbox
}
}
ORDER BY ?name
"#.to_string();
let triples = br#"
<http://example.com/bob> <http://xmlns.com/foaf/0.1/name> "Bob" .
<http://example.com/alice> <http://xmlns.com/foaf/0.1/name> "Alice" .
"#.as_ref();
let options = QueryOptions::default().with_service_handler(Box::new(TwoServiceTest));
let results = do_query(triples, query, options).unwrap();
let collected = results.into_values_iter().map(move |b| b.unwrap()).collect::<Vec<_>>();
let solution = vec![
vec![ Some(literal("Alice".to_string())), Some(mailto("alice@example.com".to_string())) ],
vec![ Some(literal("Bob".to_string())), Some(mailto("bob@example.com".to_string())) ],
];
assert_eq!(collected, solution);
}
fn ex(id: String) -> Term { fn ex(id: String) -> Term {
Term::NamedNode(NamedNode::parse(format!("http://example.com/{}", &id)).unwrap()) Term::NamedNode(NamedNode::parse(format!("http://example.com/{}", &id)).unwrap())
} }

Loading…
Cancel
Save