1 // Copyright 2018-2019 Mozilla
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 // this file except in compliance with the License. You may obtain a copy of the
5 // License at http://www.apache.org/licenses/LICENSE-2.0
6 // Unless required by applicable law or agreed to in writing, software distributed
7 // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8 // CONDITIONS OF ANY KIND, either express or implied. See the License for the
9 // specific language governing permissions and limitations under the License.
10 
11 use rkv::{
12     Manager,
13     Rkv,
14 };
15 use std::{
16     fs,
17     sync::Arc,
18 };
19 use tempfile::Builder;
20 
21 #[test]
22 // Identical to the same-named unit test, but this one confirms that it works
23 // via the public MANAGER singleton.
test_same()24 fn test_same() {
25     let root = Builder::new().prefix("test_same_singleton").tempdir().expect("tempdir");
26     fs::create_dir_all(root.path()).expect("dir created");
27 
28     let p = root.path();
29     assert!(Manager::singleton().read().unwrap().get(p).expect("success").is_none());
30 
31     let created_arc = Manager::singleton().write().unwrap().get_or_create(p, Rkv::new).expect("created");
32     let fetched_arc = Manager::singleton().read().unwrap().get(p).expect("success").expect("existed");
33     assert!(Arc::ptr_eq(&created_arc, &fetched_arc));
34 }
35