From cd1b9fcd3ebbe98a4c343573d7a7c3a40102acc6 Mon Sep 17 00:00:00 2001 From: Vadim Date: Sat, 13 Jan 2024 21:05:26 +0200 Subject: [PATCH] test(config): bump project dependencies, add tests (#56) - [x] update cargo dependencies; - [x] add tests for configuration submodules; --- Cargo.lock | 72 +++++++++---------- LICENSE | 2 +- .../artifact/configuration/mod.rs | 17 +++-- .../artifact/configuration/tests/mod.rs | 42 +++++++++++ src/data_pipeline/configuration/mod.rs | 3 + src/data_pipeline/configuration/tests/mod.rs | 25 +++++++ src/data_pipeline/mongo/configuration/mod.rs | 13 ++-- .../mongo/configuration/tests/mod.rs | 24 +++++++ 8 files changed, 146 insertions(+), 52 deletions(-) create mode 100644 src/data_pipeline/artifact/configuration/tests/mod.rs create mode 100644 src/data_pipeline/configuration/tests/mod.rs create mode 100644 src/data_pipeline/mongo/configuration/tests/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 3260762..1f5d381 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,9 +156,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.5" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "bincode" @@ -336,34 +336,28 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca89a0e215bab21874660c67903c5f143333cab1da83d041c7ded6053774751" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "cfg-if", "crossbeam-epoch", "crossbeam-utils", ] [[package]] name = "crossbeam-epoch" -version = "0.9.17" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e3681d554572a651dda4186cd47240627c3d0114d45a95f6ad27f2f22e7548d" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" dependencies = [ - "autocfg", - "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.18" +version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a430a770ebd84726f584a90ee7f020d28db52c6d02138900f22341f866d39c" -dependencies = [ - "cfg-if", -] +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] name = "crypto-common" @@ -648,9 +642,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "js-sys", @@ -667,9 +661,9 @@ checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" [[package]] name = "h2" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +checksum = "b553656127a00601c8ae5590fcfdc118e4083a7924b6cf4ffc1ea4b99dc429d7" dependencies = [ "bytes", "fnv", @@ -929,9 +923,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -942,7 +936,7 @@ version = "8.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6971da4d9c3aa03c3d8f3ff0f4155b534aad021292003895a469716b2a230378" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "pem", "ring 0.16.20", "serde", @@ -958,9 +952,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.151" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libm" @@ -1620,7 +1614,7 @@ version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", "bytes", "encoding_rs", "futures-core", @@ -1846,7 +1840,7 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" dependencies = [ - "base64 0.21.5", + "base64 0.21.7", ] [[package]] @@ -2549,9 +2543,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2559,9 +2553,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", @@ -2574,9 +2568,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.39" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" +checksum = "bde2032aeb86bdfaecc8b261eef3cba735cc426c1f3a3416d1e0791be95fc461" dependencies = [ "cfg-if", "js-sys", @@ -2586,9 +2580,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2596,9 +2590,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", @@ -2609,9 +2603,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.89" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "wasm-timer" @@ -2630,9 +2624,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.66" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" +checksum = "58cd2333b6e0be7a39605f0e255892fd7418a682d8da8fe042fe25128794d2ed" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/LICENSE b/LICENSE index c71e3a1..5cbdcd6 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2023 rfprod. +Copyright (c) 2023-2024 rfprod. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/data_pipeline/artifact/configuration/mod.rs b/src/data_pipeline/artifact/configuration/mod.rs index e8d5449..ef92263 100644 --- a/src/data_pipeline/artifact/configuration/mod.rs +++ b/src/data_pipeline/artifact/configuration/mod.rs @@ -4,9 +4,9 @@ use colored::Colorize; use std::env::{self}; /// Artifact module context configuration. -pub fn choose_context(contexts: [&str; 2], context_arg: Option) -> usize { +pub fn choose_context(contexts: [&str; 2], context: Option) -> usize { let p = ArtifactConfiguration::new(contexts); - p.choose_context(context_arg) + p.choose_context(context) } /// Artifact module file system configuration. @@ -33,10 +33,10 @@ impl<'a> ArtifactConfiguration<'a> { } /// Artifact module context configuration. - fn choose_context(&self, context_arg: Option) -> usize { - let is_some = context_arg.is_some(); - let context_arg_input = if is_some { - match context_arg.unwrap().trim().parse::() { + fn choose_context(&self, context: Option) -> usize { + let is_some = context.is_some(); + let context_input = if is_some { + match context.unwrap().trim().parse::() { Ok(value) => value, Err(_) => String::new(), } @@ -46,7 +46,7 @@ impl<'a> ArtifactConfiguration<'a> { let mut index = usize::MAX; for (i, ctx) in self.contexts.iter().enumerate() { - if ctx.to_owned().eq(context_arg_input.as_str()) { + if ctx.to_owned().eq(context_input.as_str()) { index = i; break; } @@ -83,3 +83,6 @@ impl<'a> ArtifactConfiguration<'a> { } } } + +#[cfg(test)] +mod tests; diff --git a/src/data_pipeline/artifact/configuration/tests/mod.rs b/src/data_pipeline/artifact/configuration/tests/mod.rs new file mode 100644 index 0000000..e95bdc6 --- /dev/null +++ b/src/data_pipeline/artifact/configuration/tests/mod.rs @@ -0,0 +1,42 @@ +mod artifact_configuration { + use crate::data_pipeline::artifact::{configuration::ArtifactConfiguration, CONTEXTS}; + + #[test] + fn choose_context() { + let program = ArtifactConfiguration::new(CONTEXTS); + let contexts = program.contexts; + for (i, record) in contexts.iter().enumerate() { + let index = program.choose_context(Some(record.to_string())); + assert_eq!(i, index); + } + } + + #[test] + fn fs_config() { + let program = ArtifactConfiguration::new(CONTEXTS); + let collection = String::from("test"); + let config = program.fs_config(collection.clone()); + + let json_base_path = String::from("./.data/output/github/"); + assert_eq!( + config.json_collection_path, + json_base_path + &collection + "/" + ); + + let partial_artifact_base_path = "/.data/artifact/github/"; + assert!(config + .artifact_base_path + .contains(partial_artifact_base_path)); + + let artifact_file_name_prefix = String::from("github-"); + assert_eq!( + config.artifact_file_name, + artifact_file_name_prefix.clone() + &collection + ".tar.gz" + ); + + assert_eq!( + config.encrypted_artifact_file_name, + artifact_file_name_prefix + &collection + ".tar.gz.gpg" + ) + } +} diff --git a/src/data_pipeline/configuration/mod.rs b/src/data_pipeline/configuration/mod.rs index f6dc327..d491b5d 100644 --- a/src/data_pipeline/configuration/mod.rs +++ b/src/data_pipeline/configuration/mod.rs @@ -188,3 +188,6 @@ impl<'a> DataPipelineConfiguration<'a> { String::new() } } + +#[cfg(test)] +mod tests; diff --git a/src/data_pipeline/configuration/tests/mod.rs b/src/data_pipeline/configuration/tests/mod.rs new file mode 100644 index 0000000..90b1850 --- /dev/null +++ b/src/data_pipeline/configuration/tests/mod.rs @@ -0,0 +1,25 @@ +mod data_pipeline_configuration { + use crate::data_pipeline::{ + artifact::CONTEXTS, configuration::DataPipelineConfiguration, mongo::COLLECTIONS, + }; + + #[test] + fn choose_context() { + let program = DataPipelineConfiguration::new(CONTEXTS, COLLECTIONS); + let contexts = program.contexts; + for (i, record) in contexts.iter().enumerate() { + let index = program.choose_context(Some(i.to_string())); + assert_eq!(contexts.get(index), Some(record)); + } + } + + #[test] + fn choose_collection() { + let program = DataPipelineConfiguration::new(CONTEXTS, COLLECTIONS); + let collections = program.collections; + for (i, record) in collections.iter().enumerate() { + let index = program.choose_collection(Some(i.to_string())); + assert_eq!(collections.get(index), Some(record)); + } + } +} diff --git a/src/data_pipeline/mongo/configuration/mod.rs b/src/data_pipeline/mongo/configuration/mod.rs index 760fe26..41746a0 100644 --- a/src/data_pipeline/mongo/configuration/mod.rs +++ b/src/data_pipeline/mongo/configuration/mod.rs @@ -23,10 +23,10 @@ impl<'a> MongoDbConfiguration<'a> { } /// MongoDb module collection configuration. - pub fn choose_collection(&self, collection_arg: Option) -> usize { - let is_some = collection_arg.is_some(); - let collection_arg_input = if is_some { - match collection_arg.unwrap().trim().parse::() { + pub fn choose_collection(&self, collection: Option) -> usize { + let is_some = collection.is_some(); + let collection_input = if is_some { + match collection.unwrap().trim().parse::() { Ok(value) => value, Err(_) => String::new(), } @@ -36,7 +36,7 @@ impl<'a> MongoDbConfiguration<'a> { let mut index = usize::MAX; for (i, ctx) in self.collections.iter().enumerate() { - if ctx.to_owned().eq(collection_arg_input.as_str()) { + if ctx.to_owned().eq(collection_input.as_str()) { index = i; break; } @@ -100,3 +100,6 @@ impl<'a> MongoDbConfiguration<'a> { MongoDbFileConfig { json_data_dir } } } + +#[cfg(test)] +mod tests; diff --git a/src/data_pipeline/mongo/configuration/tests/mod.rs b/src/data_pipeline/mongo/configuration/tests/mod.rs new file mode 100644 index 0000000..c75b532 --- /dev/null +++ b/src/data_pipeline/mongo/configuration/tests/mod.rs @@ -0,0 +1,24 @@ +mod mongo_db_configuration { + use crate::data_pipeline::mongo::{configuration::MongoDbConfiguration, COLLECTIONS}; + + #[test] + fn collections() { + let program = MongoDbConfiguration::new(COLLECTIONS); + let collections = program.collections; + for (i, record) in collections.iter().enumerate() { + let index = program.choose_collection(Some(record.to_string())); + assert_eq!(i, index); + } + } + + #[test] + fn fs_config() { + let program = MongoDbConfiguration::new(COLLECTIONS); + let collection = String::from("test"); + let config = program.fs_config(collection.clone()); + + let json_base_path = String::from("/.data/output/github/"); + let partial_json_data_dir = json_base_path + &collection + "/"; + assert!(config.json_data_dir.contains(&partial_json_data_dir)); + } +}