summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-05-04 09:15:43 +0200
committerGitHub <noreply@github.com>2017-05-04 09:15:43 +0200
commita5857fa64c949c9f2c9dea3036d870bd592272cc (patch)
tree41231d19afd970ca693b2364d95260f615f69bbc
parent4257ec10268fef06d5888c48f9fc8f9e6f35c5ba (diff)
parent89d8abefe7742e6dfcc73c29b5a453cf84374a8e (diff)
downloadimag-a5857fa64c949c9f2c9dea3036d870bd592272cc.zip
imag-a5857fa64c949c9f2c9dea3036d870bd592272cc.tar.gz
Merge pull request #932 from matthiasbeyer/libimagstore/configuration-tests
Add tests for configuration
-rw-r--r--libimagstore/Cargo.toml1
-rw-r--r--libimagstore/src/configuration.rs346
-rw-r--r--libimagstore/src/lib.rs1
3 files changed, 347 insertions, 1 deletions
diff --git a/libimagstore/Cargo.toml b/libimagstore/Cargo.toml
index f2e12cc..99ee6c1 100644
--- a/libimagstore/Cargo.toml
+++ b/libimagstore/Cargo.toml
@@ -24,6 +24,7 @@ toml = "^0.4"
version = "2.0.1"
crossbeam = "0.2.*"
walkdir = "1.0.*"
+itertools = "0.6.*"
[dependencies.libimagerror]
path = "../libimagerror"
diff --git a/libimagstore/src/configuration.rs b/libimagstore/src/configuration.rs
index fd73674..06e0d3c 100644
--- a/libimagstore/src/configuration.rs
+++ b/libimagstore/src/configuration.rs
@@ -329,6 +329,7 @@ impl AspectConfig {
}
fn get_aspect_names_for_aspect_position(config_name: &'static str, value: &Option<Value>) -> Vec<String> {
+ use itertools::Itertools;
let mut v = vec![];
match *value {
@@ -348,7 +349,350 @@ fn get_aspect_names_for_aspect_position(config_name: &'static str, value: &Optio
None => warn!("No store configuration, cannot get '{}'", config_name),
_ => warn!("Configuration is not a table"),
}
- v
+
+ v.into_iter().unique().collect()
}
+#[cfg(test)]
+mod tests {
+ use toml::de::from_str as toml_from_str;
+ use configuration::*;
+
+ #[test]
+ fn test_implicit_store_create_allowed_no_toml() {
+ assert!(!config_implicit_store_create_allowed(None));
+ }
+
+ #[test]
+ fn test_implicit_store_create_allowed_toml_empty() {
+ let config = toml_from_str("").unwrap();
+ assert!(!config_implicit_store_create_allowed(Some(config).as_ref()));
+ }
+
+ #[test]
+ fn test_implicit_store_create_allowed_toml_false() {
+ let config = toml_from_str(r#"
+ implicit-create = false
+ "#).unwrap();
+
+ assert!(!config_implicit_store_create_allowed(Some(config).as_ref()));
+ }
+
+ #[test]
+ fn test_implicit_store_create_allowed_toml_true() {
+ let config = toml_from_str(r#"
+ implicit-create = true
+ "#).unwrap();
+
+ assert!(config_implicit_store_create_allowed(Some(config).as_ref()));
+ }
+
+ #[test]
+ fn test_get_store_unload_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ let names = get_store_unload_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_store_unload_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ store-unload-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_store_unload_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_store_unload_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ store-unload-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_store_unload_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_pre_create_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_pre_create_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_create_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ pre-create-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_pre_create_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_create_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ pre-create-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_pre_create_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_post_create_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_post_create_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_post_create_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ post-create-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_post_create_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_post_create_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ post-create-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_post_create_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_pre_retrieve_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_pre_retrieve_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_retrieve_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ pre-retrieve-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_pre_retrieve_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_retrieve_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ pre-retrieve-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_pre_retrieve_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_post_retrieve_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_post_retrieve_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_post_retrieve_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ post-retrieve-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_post_retrieve_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_post_retrieve_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ post-retrieve-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_post_retrieve_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_pre_update_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_pre_update_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_update_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ pre-update-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_pre_update_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_update_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ pre-update-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_pre_update_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_post_update_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_post_update_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_post_update_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ post-update-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_post_update_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_post_update_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ post-update-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_post_update_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_pre_delete_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_pre_delete_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_delete_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ pre-delete-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_pre_delete_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_delete_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ pre-delete-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_pre_delete_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_post_delete_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_post_delete_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_post_delete_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ post-delete-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_post_delete_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_post_delete_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ post-delete-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_post_delete_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_pre_move_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_pre_move_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_move_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ pre-move-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_pre_move_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_pre_move_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ pre-move-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_pre_move_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_post_move_aspect_names_not_existent() {
+ let config = toml_from_str("").unwrap();
+ assert!(get_post_move_aspect_names(&Some(config)).is_empty());
+ }
+
+ #[test]
+ fn test_get_post_move_aspect_names_empty() {
+ let config = toml_from_str(r#"
+ post-move-hook-aspects = [ ]
+ "#).unwrap();
+ let names = get_post_move_aspect_names(&Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_post_move_aspect_names_one_elem() {
+ let config = toml_from_str(r#"
+ post-move-hook-aspects = [ "example" ]
+ "#).unwrap();
+ let names = get_post_move_aspect_names(&Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("example", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_aspect_names_for_aspect_position_arbitrary_empty() {
+ let config = toml_from_str(r#"
+ test-key = [ ]
+ "#).unwrap();
+ let names = get_aspect_names_for_aspect_position("test-key", &Some(config));
+ assert!(names.is_empty());
+ }
+
+ #[test]
+ fn test_get_aspect_names_for_aspect_position_arbitrary_one() {
+ let config = toml_from_str(r#"
+ test-key = [ "test-value" ]
+ "#).unwrap();
+ let names = get_aspect_names_for_aspect_position("test-key", &Some(config));
+ assert_eq!(1, names.len());
+ assert_eq!("test-value", names.iter().next().unwrap());
+ }
+
+ #[test]
+ fn test_get_aspect_names_for_aspect_position_arbitrary_duplicated() {
+ let config = toml_from_str(r#"
+ test-key = [ "test-value", "test-value" ]
+ "#).unwrap();
+ let names = get_aspect_names_for_aspect_position("test-key", &Some(config));
+ assert_eq!(1, names.len());
+ let mut iter = names.iter();
+ assert_eq!("test-value", iter.next().unwrap());
+ assert!(iter.next().is_none());
+ }
+
+}
diff --git a/libimagstore/src/lib.rs b/libimagstore/src/lib.rs
index 56c3a74..835704a 100644
--- a/libimagstore/src/lib.rs
+++ b/libimagstore/src/lib.rs
@@ -42,6 +42,7 @@ extern crate toml;
extern crate semver;
extern crate crossbeam;
extern crate walkdir;
+extern crate itertools;
#[macro_use] extern crate libimagerror;
#[macro_use] extern crate libimagutil;