Merge pull request #1044 from matthiasbeyer/libimagrt/feature-testing
Add store extraction to Runtime
This commit is contained in:
commit
5626a365c6
4 changed files with 49 additions and 0 deletions
|
@ -35,3 +35,9 @@ path = "../../../lib/etc/libimagutil"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["testing"]
|
features = ["testing"]
|
||||||
|
|
||||||
|
[dev-dependencies.libimagrt]
|
||||||
|
version = "0.4.0"
|
||||||
|
path = "../../../lib/core/libimagrt"
|
||||||
|
default-features = false
|
||||||
|
features = ["testing"]
|
||||||
|
|
||||||
|
|
|
@ -27,3 +27,11 @@ toml-query = "0.3.0"
|
||||||
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.4.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
|
libimagerror = { version = "0.4.0", path = "../../../lib/core/libimagerror" }
|
||||||
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }
|
libimagutil = { version = "0.4.0", path = "../../../lib/etc/libimagutil" }
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = []
|
||||||
|
|
||||||
|
# Enable testing functionality. Used for building the libimagrt for testing CLI
|
||||||
|
# apps. Do not use in production!
|
||||||
|
testing = []
|
||||||
|
|
||||||
|
|
|
@ -315,6 +315,29 @@ impl<'a> Runtime<'a> {
|
||||||
"generate-completion"
|
"generate-completion"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extract the Store object from the Runtime object, destroying the Runtime object
|
||||||
|
///
|
||||||
|
/// # Warning
|
||||||
|
///
|
||||||
|
/// This function is for testing _only_! It can be used to re-build a Runtime object with an
|
||||||
|
/// alternative Store.
|
||||||
|
#[cfg(feature = "testing")]
|
||||||
|
pub fn extract_store(self) -> Store {
|
||||||
|
self.store
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Re-set the Store object within
|
||||||
|
///
|
||||||
|
/// # Warning
|
||||||
|
///
|
||||||
|
/// This function is for testing _only_! It can be used to re-build a Runtime object with an
|
||||||
|
/// alternative Store.
|
||||||
|
#[cfg(feature = "testing")]
|
||||||
|
pub fn with_store(mut self, s: Store) -> Self {
|
||||||
|
self.store = s;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Initialize the internal logger
|
/// Initialize the internal logger
|
||||||
fn init_logger(is_debugging: bool, is_verbose: bool, colored: bool) {
|
fn init_logger(is_debugging: bool, is_verbose: bool, colored: bool) {
|
||||||
use std::env::var as env_var;
|
use std::env::var as env_var;
|
||||||
|
|
|
@ -108,6 +108,18 @@ macro_rules! make_mock_app {
|
||||||
let cli_app = MockLinkApp::new(cli_args);
|
let cli_app = MockLinkApp::new(cli_args);
|
||||||
Runtime::with_configuration(cli_app, generate_minimal_test_config())
|
Runtime::with_configuration(cli_app, generate_minimal_test_config())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset_test_runtime<'a>(mut args: Vec<&'static str>, old_runtime: Runtime)
|
||||||
|
-> Result<Runtime<'a>, RuntimeError>
|
||||||
|
{
|
||||||
|
let mut cli_args = vec![$appname, "--rtp", "/tmp"];
|
||||||
|
|
||||||
|
cli_args.append(&mut args);
|
||||||
|
|
||||||
|
let cli_app = MockLinkApp::new(cli_args);
|
||||||
|
Runtime::with_configuration(cli_app, generate_minimal_test_config())
|
||||||
|
.map(|rt| rt.with_store(old_runtime.extract_store()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue