diff --git a/rust/nix-expr/src/eval_state.rs b/rust/nix-expr/src/eval_state.rs index b631595..99e60cf 100644 --- a/rust/nix-expr/src/eval_state.rs +++ b/rust/nix-expr/src/eval_state.rs @@ -154,7 +154,7 @@ impl EvalState { /// use nix_expr::value::Value; /// /// # fn main() -> anyhow::Result<()> { - /// # let mut es = EvalState::new(Store::open("auto", [])?, [])?; + /// # let mut es = EvalState::new(Store::open(None, [])?, [])?; /// let v: Value = es.eval_from_string("42", ".")?; /// assert_eq!(es.require_int(&v)?, 42); /// # Ok(()) @@ -672,7 +672,7 @@ mod tests { fn eval_state_new_and_drop() { gc_registering_current_thread(|| { // very basic test: make sure initialization doesn't crash - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let _e = EvalState::new(store, []).unwrap(); }) .unwrap(); @@ -681,7 +681,7 @@ mod tests { #[test] fn weak_ref() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let es = EvalState::new(store, []).unwrap(); let weak = es.weak_ref(); let _es = weak.upgrade().unwrap(); @@ -694,7 +694,7 @@ mod tests { gc_registering_current_thread(|| { let weak = { // Use a slightly different URL which is unique in the test suite, to bypass the global store cache - let store = Store::open("auto?foo=bar", HashMap::new()).unwrap(); + let store = Store::open(Some("auto?foo=bar"), HashMap::new()).unwrap(); let es = EvalState::new(store, []).unwrap(); es.weak_ref() }; @@ -715,11 +715,11 @@ mod tests { writeln!(test_file0, "{integer0}").unwrap(); writeln!(test_file1, "{integer1}").unwrap(); gc_registering_current_thread(|| { - let mut es = EvalState::new(Store::open("auto", HashMap::new()).unwrap(), []).unwrap(); + let mut es = EvalState::new(Store::open(None, HashMap::new()).unwrap(), []).unwrap(); assert!(es.eval_from_string(import_expression, "").is_err()); let mut es = EvalState::new( - Store::open("auto", HashMap::new()).unwrap(), + Store::open(None, HashMap::new()).unwrap(), [ format!("test_file0={}", test_file0.path().to_str().unwrap()).as_str(), format!("test_file1={}", test_file1.path().to_str().unwrap()).as_str(), @@ -738,7 +738,7 @@ mod tests { #[test] fn eval_state_eval_from_string() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.eval_from_string("1", "").unwrap(); let v2 = v.clone(); @@ -755,7 +755,7 @@ mod tests { #[test] fn eval_state_value_bool() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.eval_from_string("true", "").unwrap(); es.force(&v).unwrap(); @@ -768,7 +768,7 @@ mod tests { #[test] fn eval_state_value_int() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.eval_from_string("1", "").unwrap(); es.force(&v).unwrap(); @@ -783,7 +783,7 @@ mod tests { #[test] fn eval_state_require_int_forces_thunk() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let f = es.eval_from_string("x: x + 1", "").unwrap(); let a = es.eval_from_string("2", "").unwrap(); @@ -810,7 +810,7 @@ mod tests { #[test] fn make_thunk_helper_works() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = make_thunk(&mut es, "1"); let t = es.value_type_unforced(&v); @@ -822,7 +822,7 @@ mod tests { #[test] fn eval_state_value_attrs_names_empty() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.eval_from_string("{ }", "").unwrap(); es.force(&v).unwrap(); @@ -837,7 +837,7 @@ mod tests { #[test] fn eval_state_require_attrs_names_unsorted_forces_thunk() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = make_thunk(&mut es, "{ a = 1; b = 2; }"); let t = es.value_type_unforced(&v); @@ -851,7 +851,7 @@ mod tests { #[test] fn eval_state_require_attrs_names_unsorted_bad_type() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.eval_from_string("1", "").unwrap(); es.force(&v).unwrap(); @@ -868,7 +868,7 @@ mod tests { #[test] fn eval_state_value_attrs_names_example() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let expr = r#"{ a = throw "nope a"; b = throw "nope b"; }"#; let v = es.eval_from_string(expr, "").unwrap(); @@ -883,7 +883,7 @@ mod tests { #[test] fn eval_state_require_attrs_select() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let expr = r#"{ a = "aye"; b = "bee"; }"#; let v = es.eval_from_string(expr, "").unwrap(); @@ -910,7 +910,7 @@ mod tests { #[test] fn eval_state_require_attrs_select_forces_thunk() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let expr = r#"{ a = "aye"; b = "bee"; }"#; let v = make_thunk(&mut es, expr); @@ -924,7 +924,7 @@ mod tests { #[test] fn eval_state_require_attrs_select_error() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let expr = r#"{ a = throw "oh no the error"; }"#; let v = es.eval_from_string(expr, "").unwrap(); @@ -945,7 +945,7 @@ mod tests { #[test] fn eval_state_require_attrs_select_opt() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let expr = r#"{ a = "aye"; b = "bee"; }"#; let v = es.eval_from_string(expr, "").unwrap(); @@ -962,7 +962,7 @@ mod tests { #[test] fn eval_state_require_attrs_select_opt_forces_thunk() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let expr = r#"{ a = "aye"; b = "bee"; }"#; let v = make_thunk(&mut es, expr); @@ -976,7 +976,7 @@ mod tests { #[test] fn eval_state_require_attrs_select_opt_error() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let expr = r#"{ a = throw "oh no the error"; }"#; let v = es.eval_from_string(expr, "").unwrap(); @@ -997,7 +997,7 @@ mod tests { #[test] fn eval_state_value_string() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.eval_from_string("\"hello\"", "").unwrap(); es.force(&v).unwrap(); @@ -1012,7 +1012,7 @@ mod tests { #[test] fn eval_state_value_string_forces_thunk() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = make_thunk(&mut es, "\"hello\""); assert!(es.value_type_unforced(&v).is_none()); @@ -1025,7 +1025,7 @@ mod tests { #[test] fn eval_state_value_string_unexpected_bool() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.eval_from_string("true", "").unwrap(); es.force(&v).unwrap(); @@ -1043,7 +1043,7 @@ mod tests { #[test] fn eval_state_value_string_unexpected_path_value() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.eval_from_string("/foo", "").unwrap(); es.force(&v).unwrap(); @@ -1060,7 +1060,7 @@ mod tests { #[test] fn eval_state_value_string_bad_utf() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es .eval_from_string("builtins.substring 0 1 \"ΓΌ\"", "") @@ -1081,7 +1081,7 @@ mod tests { #[test] fn eval_state_value_string_unexpected_context() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es .eval_from_string("(derivation { name = \"hello\"; system = \"dummy\"; builder = \"cmd.exe\"; }).outPath", "") @@ -1100,7 +1100,7 @@ mod tests { #[test] fn eval_state_new_string() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.new_value_str("hello").unwrap(); es.force(&v).unwrap(); @@ -1115,7 +1115,7 @@ mod tests { #[test] fn eval_state_new_string_empty() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.new_value_str("").unwrap(); es.force(&v).unwrap(); @@ -1130,7 +1130,7 @@ mod tests { #[test] fn eval_state_new_string_invalid() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let r = es.new_value_str("hell\0no"); match r { @@ -1149,7 +1149,7 @@ mod tests { #[test] fn eval_state_new_int() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.new_value_int(42).unwrap(); es.force(&v).unwrap(); @@ -1164,7 +1164,7 @@ mod tests { #[test] fn eval_state_value_attrset() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es.eval_from_string("{ }", "").unwrap(); es.force(&v).unwrap(); @@ -1177,7 +1177,7 @@ mod tests { #[test] fn eval_state_value_list() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es .eval_from_string("[ ]", "") @@ -1192,7 +1192,7 @@ mod tests { #[test] fn eval_state_realise_string() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let expr = r#" '' @@ -1239,7 +1239,7 @@ mod tests { #[test] fn eval_state_call() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let f = es.eval_from_string("x: x + 1", "").unwrap(); let a = es.eval_from_string("2", "").unwrap(); @@ -1256,7 +1256,7 @@ mod tests { #[test] fn eval_state_call_multi() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); // This is a function that takes two arguments. let f = es.eval_from_string("x: y: x - y", "").unwrap(); @@ -1274,7 +1274,7 @@ mod tests { #[test] fn eval_state_apply() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); // This is a function that takes two arguments. let f = es.eval_from_string("x: x + 1", "").unwrap(); @@ -1293,7 +1293,7 @@ mod tests { #[test] fn eval_state_call_fail_body() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let f = es.eval_from_string("x: x + 1", "").unwrap(); let a = es.eval_from_string("true", "").unwrap(); @@ -1314,7 +1314,7 @@ mod tests { #[test] fn eval_state_call_multi_fail_body() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); // This is a function that takes two arguments. let f = es.eval_from_string("x: y: x - y", "").unwrap(); @@ -1337,7 +1337,7 @@ mod tests { #[test] fn eval_state_apply_fail_body() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let f = es.eval_from_string("x: x + 1", "").unwrap(); let a = es.eval_from_string("true", "").unwrap(); @@ -1362,7 +1362,7 @@ mod tests { #[test] fn eval_state_call_fail_args() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let f = es.eval_from_string("{x}: x + 1", "").unwrap(); let a = es.eval_from_string("{}", "").unwrap(); @@ -1383,7 +1383,7 @@ mod tests { #[test] fn eval_state_call_multi_fail_args() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); // This is a function that takes two arguments. let f = es.eval_from_string("{x}: {y}: x - y", "").unwrap(); @@ -1407,7 +1407,7 @@ mod tests { #[test] fn eval_state_apply_fail_args_lazy() { gc_registering_current_thread(|| { - let store = Store::open("auto", HashMap::new()).unwrap(); + let store = Store::open(None, HashMap::new()).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let f = es.eval_from_string("{x}: x + 1", "").unwrap(); let a = es.eval_from_string("{}", "").unwrap(); @@ -1440,7 +1440,7 @@ mod tests { let mut es = EvalState::new( Store::open( - "local", + Some("local"), HashMap::from([ ("store", store_path), ("state", state_path), @@ -1507,7 +1507,7 @@ mod tests { #[test] fn eval_state_primop_anon_call() { gc_registering_current_thread(|| { - let store = Store::open("auto", []).unwrap(); + let store = Store::open(None, []).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let bias: Arc> = Arc::new(Mutex::new(0)); let bias_control = bias.clone(); @@ -1549,7 +1549,7 @@ mod tests { #[test] fn eval_state_primop_anon_call_throw() { gc_registering_current_thread(|| { - let store = Store::open("auto", []).unwrap(); + let store = Store::open(None, []).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let f = { let es: &mut EvalState = &mut es; @@ -1588,7 +1588,7 @@ mod tests { #[test] fn eval_state_primop_anon_call_no_args() { gc_registering_current_thread(|| { - let store = Store::open("auto", []).unwrap(); + let store = Store::open(None, []).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es .new_value_thunk( @@ -1609,7 +1609,7 @@ mod tests { #[test] fn eval_state_primop_anon_call_no_args_lazy() { gc_registering_current_thread(|| { - let store = Store::open("auto", []).unwrap(); + let store = Store::open(None, []).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let v = es .new_value_thunk( @@ -1642,7 +1642,7 @@ mod tests { #[test] pub fn eval_state_primop_custom() { gc_registering_current_thread(|| { - let store = Store::open("auto", []).unwrap(); + let store = Store::open(None, []).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let primop = primop::PrimOp::new( &mut es, @@ -1675,7 +1675,7 @@ mod tests { #[test] pub fn eval_state_primop_custom_throw() { gc_registering_current_thread(|| { - let store = Store::open("auto", []).unwrap(); + let store = Store::open(None, []).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let primop = primop::PrimOp::new( &mut es, @@ -1709,7 +1709,7 @@ mod tests { #[test] pub fn eval_state_new_value_attrs_from_slice_empty() { gc_registering_current_thread(|| { - let store = Store::open("auto", []).unwrap(); + let store = Store::open(None, []).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let attrs = es.new_value_attrs([]).unwrap(); let t = es.value_type(&attrs).unwrap(); @@ -1723,7 +1723,7 @@ mod tests { #[test] pub fn eval_state_new_value_attrs_from_vec() { gc_registering_current_thread(|| { - let store = Store::open("auto", []).unwrap(); + let store = Store::open(None, []).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let attrs = { let a = es.new_value_int(1).unwrap(); @@ -1750,7 +1750,7 @@ mod tests { #[test] pub fn eval_state_new_value_attrs_from_hashmap() { gc_registering_current_thread(|| { - let store = Store::open("auto", []).unwrap(); + let store = Store::open(None, []).unwrap(); let mut es = EvalState::new(store, []).unwrap(); let attrs = { let a = es.new_value_int(1).unwrap(); diff --git a/rust/nix-store/src/path.rs b/rust/nix-store/src/path.rs index e6b9ceb..29b6c83 100644 --- a/rust/nix-store/src/path.rs +++ b/rust/nix-store/src/path.rs @@ -77,7 +77,7 @@ mod tests { #[test] #[cfg(nix_at_least = "2.26" /* get_storedir */)] fn store_path_name() { - let mut store = crate::store::Store::open("dummy://", []).unwrap(); + let mut store = crate::store::Store::open(Some("dummy://"), []).unwrap(); let store_dir = store.get_storedir().unwrap(); let store_path_string = format!("{store_dir}/rdd4pnr4x9rqc9wgbibhngv217w2xvxl-bash-interactive-5.2p26"); diff --git a/rust/nix-store/src/store.rs b/rust/nix-store/src/store.rs index d1d5a72..8b74a85 100644 --- a/rust/nix-store/src/store.rs +++ b/rust/nix-store/src/store.rs @@ -59,7 +59,7 @@ impl StoreWeak { } /// Protects against https://github.com/NixOS/nix/issues/11979 (unless different parameters are passed, in which case it's up to luck, but you do get your own parameters as you asked for). -type StoreCacheMap = HashMap<(String, Vec<(String, String)>), StoreWeak>; +type StoreCacheMap = HashMap<(Option, Vec<(String, String)>), StoreWeak>; lazy_static! { static ref STORE_CACHE: Arc> = Arc::new(Mutex::new(HashMap::new())); @@ -71,8 +71,11 @@ pub struct Store { context: Context, } impl Store { + /// Open a store. + /// + /// See [nix_c_raw::store_open] for more information. pub fn open<'a, 'b>( - url: &str, + url: Option<&str>, params: impl IntoIterator, ) -> Result { let params = params @@ -83,7 +86,7 @@ impl Store { let mut store_cache = STORE_CACHE .lock() .map_err(|_| Error::msg("Failed to lock store cache. This should never happen."))?; - match store_cache.entry((url.to_string(), params)) { + match store_cache.entry((url.map(Into::into), params)) { std::collections::hash_map::Entry::Occupied(mut e) => { if let Some(store) = e.get().upgrade() { Ok(store) @@ -107,7 +110,7 @@ impl Store { } } fn open_uncached<'a, 'b>( - url: &str, + url: Option<&str>, params: impl IntoIterator, ) -> Result { let x = INIT.as_ref(); @@ -121,7 +124,14 @@ impl Store { let mut context: Context = Context::new(); - let uri_ptr = CString::new(url)?; + let uri_cstring = match url { + Some(url) => Some(CString::new(url)?), + None => None, + }; + let uri_ptr = uri_cstring + .as_ref() + .map(|s| s.as_ptr()) + .unwrap_or(null_mut()); // this intermediate value must be here and must not be moved // because it owns the data the `*const c_char` pointers point to. @@ -141,13 +151,8 @@ impl Store { .chain(std::iter::once(null_mut())) // signal the end of the array .collect(); - let store = unsafe { - check_call!(raw::store_open( - &mut context, - uri_ptr.as_ptr(), - params.as_mut_ptr() - )) - }?; + let store = + unsafe { check_call!(raw::store_open(&mut context, uri_ptr, params.as_mut_ptr())) }?; if store.is_null() { panic!("nix_c_store_open returned a null pointer without an error"); } @@ -232,21 +237,29 @@ mod tests { use super::*; + #[test] + fn none_works() { + let res = Store::open(None, HashMap::new()); + res.unwrap(); + } + #[test] fn auto_works() { - let res = Store::open("auto", HashMap::new()); + // This is not actually a given. + // Maybe whatever is in NIX_REMOTE or nix.conf is really important. + let res = Store::open(Some("auto"), HashMap::new()); res.unwrap(); } #[test] fn invalid_uri_fails() { - let res = Store::open("invalid://uri", HashMap::new()); + let res = Store::open(Some("invalid://uri"), HashMap::new()); assert!(res.is_err()); } #[test] fn get_uri() { - let mut store = Store::open("auto", HashMap::new()).unwrap(); + let mut store = Store::open(None, HashMap::new()).unwrap(); let uri = store.get_uri().unwrap(); assert!(!uri.is_empty()); // must be ascii @@ -258,7 +271,7 @@ mod tests { #[test] #[ignore] // Needs network access fn get_uri_nixos_cache() { - let mut store = Store::open("https://cache.nixos.org/", HashMap::new()).unwrap(); + let mut store = Store::open(Some("https://cache.nixos.org/"), HashMap::new()).unwrap(); let uri = store.get_uri().unwrap(); assert_eq!(uri, "https://cache.nixos.org"); } @@ -266,7 +279,7 @@ mod tests { #[test] #[cfg(nix_at_least = "2.26" /* get_storedir */)] fn parse_store_path_ok() { - let mut store = crate::store::Store::open("dummy://", []).unwrap(); + let mut store = crate::store::Store::open(Some("dummy://"), []).unwrap(); let store_dir = store.get_storedir().unwrap(); let store_path_string = format!("{store_dir}/rdd4pnr4x9rqc9wgbibhngv217w2xvxl-bash-interactive-5.2p26"); @@ -276,7 +289,7 @@ mod tests { #[test] fn parse_store_path_fail() { - let mut store = crate::store::Store::open("dummy://", []).unwrap(); + let mut store = crate::store::Store::open(Some("dummy://"), []).unwrap(); let store_path_string = format!("bash-interactive-5.2p26"); let r = store.parse_store_path(store_path_string.as_str()); match r { @@ -289,7 +302,7 @@ mod tests { #[test] fn weak_ref() { - let mut store = Store::open("auto", HashMap::new()).unwrap(); + let mut store = Store::open(None, HashMap::new()).unwrap(); let uri = store.get_uri().unwrap(); let weak = store.weak_ref(); let mut store2 = weak.upgrade().unwrap(); @@ -300,7 +313,7 @@ mod tests { let weak = { // Concurrent tests calling Store::open will keep the weak reference to auto alive, // so for this test we need to bypass the global cache. - let store = Store::open_uncached("auto", HashMap::new()).unwrap(); + let store = Store::open_uncached(None, HashMap::new()).unwrap(); store.weak_ref() }; assert!(weak.upgrade().is_none());