From 65b97bd8c66092a7d255b0f29db7a1f9ec409519 Mon Sep 17 00:00:00 2001 From: Miroslav Kovar Date: Fri, 13 Nov 2020 10:46:54 +0100 Subject: [PATCH] Avoid using envvar to setup mocks Signed-off-by: Miroslav Kovar --- agency_client/src/httpclient.rs | 1 + agency_client/src/utils/libindy/crypto.rs | 5 +++-- agency_client/src/utils/test_utils.rs | 2 -- libvcx/src/settings.rs | 5 ----- libvcx/src/utils/devsetup.rs | 13 +++++-------- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/agency_client/src/httpclient.rs b/agency_client/src/httpclient.rs index decf823d67..763ad7824f 100644 --- a/agency_client/src/httpclient.rs +++ b/agency_client/src/httpclient.rs @@ -1,4 +1,5 @@ use std::env; +use std::io::Read; use reqwest; use reqwest::header::CONTENT_TYPE; diff --git a/agency_client/src/utils/libindy/crypto.rs b/agency_client/src/utils/libindy/crypto.rs index 4df2cca0da..1ad57c5c1d 100644 --- a/agency_client/src/utils/libindy/crypto.rs +++ b/agency_client/src/utils/libindy/crypto.rs @@ -1,9 +1,10 @@ use indy::crypto; use futures::Future; +use crate::mocking::agency_mocks_enabled; use crate::utils::error::VcxResult; pub fn pack_message(sender_vk: Option<&str>, receiver_keys: &str, msg: &[u8]) -> VcxResult> { - if ::std::env::var("DUMMY_TEST_MODE").unwrap_or("false".to_string()) == "true" { return Ok(msg.to_vec()); } + if agency_mocks_enabled() { return Ok(msg.to_vec()); } crypto::pack_message(crate::utils::wallet::get_wallet_handle(), msg, receiver_keys, sender_vk) .wait() @@ -11,7 +12,7 @@ pub fn pack_message(sender_vk: Option<&str>, receiver_keys: &str, msg: &[u8]) -> } pub fn unpack_message(msg: &[u8]) -> VcxResult> { - if ::std::env::var("DUMMY_TEST_MODE").unwrap_or("false".to_string()) == "true" { return Ok(msg.to_vec()); } + if agency_mocks_enabled() { return Ok(msg.to_vec()); } crypto::unpack_message(crate::utils::wallet::get_wallet_handle(), msg) .wait() diff --git a/agency_client/src/utils/test_utils.rs b/agency_client/src/utils/test_utils.rs index 173a858dd6..6bb7a6cf4c 100644 --- a/agency_client/src/utils/test_utils.rs +++ b/agency_client/src/utils/test_utils.rs @@ -30,7 +30,6 @@ impl SetupMocks { pub fn init() -> SetupMocks { setup(); mocking::enable_agency_mocks(); - ::std::env::set_var("DUMMY_TEST_MODE", "true"); SetupMocks } } @@ -38,7 +37,6 @@ impl SetupMocks { impl Drop for SetupMocks { fn drop(&mut self) { AgencyMockDecrypted::clear_mocks(); - ::std::env::set_var("DUMMY_TEST_MODE", "false"); reset_wallet_handle(); mocking::disable_agency_mocks(); } diff --git a/libvcx/src/settings.rs b/libvcx/src/settings.rs index 09eb7f1088..0a05cf9c8f 100644 --- a/libvcx/src/settings.rs +++ b/libvcx/src/settings.rs @@ -205,11 +205,6 @@ pub fn process_config_string(config: &str, do_validation: bool) -> VcxResult ::std::env::set_var("DUMMY_TEST_MODE", "true"), - _ => {} - }; - if do_validation { let setting = SETTINGS.read() .or(Err(VcxError::from(VcxErrorKind::InvalidConfiguration)))?; diff --git a/libvcx/src/utils/devsetup.rs b/libvcx/src/utils/devsetup.rs index 775104304e..b03e8526cc 100644 --- a/libvcx/src/utils/devsetup.rs +++ b/libvcx/src/utils/devsetup.rs @@ -6,10 +6,9 @@ use indy::WalletHandle; use rand::Rng; use serde_json::Value; -use ::{indy, init}; -use ::{settings, utils}; +use ::{init, settings, utils}; use agency_client::agency_settings; -use agency_client::mocking::AgencyMockDecrypted; +use agency_client::mocking::{AgencyMockDecrypted, enable_agency_mocks, disable_agency_mocks}; use libindy::utils::pool::reset_pool_handle; use libindy::utils::pool::tests::{create_test_ledger_config, delete_test_pool, open_test_pool}; use libindy::utils::wallet::{close_main_wallet, create_wallet, delete_wallet, reset_wallet_handle}; @@ -79,7 +78,7 @@ fn tear_down() { settings::clear_config(); reset_wallet_handle(); reset_pool_handle(); - ::std::env::set_var("DUMMY_TEST_MODE", "false"); + disable_agency_mocks(); AgencyMockDecrypted::clear_mocks(); } @@ -113,8 +112,7 @@ impl SetupMocks { pub fn init() -> SetupMocks { setup(); settings::set_config_value(settings::CONFIG_ENABLE_TEST_MODE, "true"); - agency_settings::set_config_value(settings::CONFIG_ENABLE_TEST_MODE, "true"); - ::std::env::set_var("DUMMY_TEST_MODE", "true"); + enable_agency_mocks(); SetupMocks } } @@ -213,8 +211,7 @@ impl SetupIndyMocks { pub fn init() -> SetupIndyMocks { setup(); settings::set_config_value(settings::CONFIG_ENABLE_TEST_MODE, "true"); - agency_settings::set_config_value(settings::CONFIG_ENABLE_TEST_MODE, "true"); - ::std::env::set_var("DUMMY_TEST_MODE", "true"); + enable_agency_mocks(); SetupIndyMocks {} } }