Skip to content

Commit

Permalink
Avoid using envvar to setup mocks
Browse files Browse the repository at this point in the history
Signed-off-by: Miroslav Kovar <miroslavkovar@protonmail.com>
  • Loading branch information
mirgee committed Nov 13, 2020
1 parent ec6cc7a commit 65b97bd
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions agency_client/src/httpclient.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::io::Read;

use reqwest;
use reqwest::header::CONTENT_TYPE;
Expand Down
5 changes: 3 additions & 2 deletions agency_client/src/utils/libindy/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
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<Vec<u8>> {
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()
.map_err(|err| err.into())
}

pub fn unpack_message(msg: &[u8]) -> VcxResult<Vec<u8>> {
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()
Expand Down
2 changes: 0 additions & 2 deletions agency_client/src/utils/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@ impl SetupMocks {
pub fn init() -> SetupMocks {
setup();
mocking::enable_agency_mocks();
::std::env::set_var("DUMMY_TEST_MODE", "true");
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();
}
Expand Down
5 changes: 0 additions & 5 deletions libvcx/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,6 @@ pub fn process_config_string(config: &str, do_validation: bool) -> VcxResult<u32

agency_settings::process_agency_config_string(config, do_validation)?;

match configuration["enable_test_mode"].as_str() {
Some(value) if value == "true" => ::std::env::set_var("DUMMY_TEST_MODE", "true"),
_ => {}
};

if do_validation {
let setting = SETTINGS.read()
.or(Err(VcxError::from(VcxErrorKind::InvalidConfiguration)))?;
Expand Down
13 changes: 5 additions & 8 deletions libvcx/src/utils/devsetup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {}
}
}
Expand Down

0 comments on commit 65b97bd

Please sign in to comment.