use bloock_storage::blob::Blob; use bloock_storage::config::RocksDBConfig; use rocksdb::DB as RocksDB; use std::any::type_name; fn init_rocksdb(name: &str) -> RocksDB { let config: RocksDBConfig = RocksDBConfig { path: String::from(name), create_if_missing: true, }; ::open(&config).expect("Something went wrong at init_rocksdb.") } fn type_of(_: T) -> &'static str { type_name::() } #[test] fn test_default() { { let rocksdb = init_rocksdb("default_rocks_blob"); assert_eq!( type_of(rocksdb), "rocksdb::db::DB", "RocksDB was not properly loaded" ); } let _ = RocksDB::destroy(&rocksdb::Options::default(), "default_rocks_blob"); } #[test] fn test_read_exist() { { let rocksdb = init_rocksdb("read_exist_rocks_blob"); rocksdb.put(&[1; 32], &[1; 32]).unwrap(); assert_eq!( rocksdb.get(&[1; 32]).unwrap(), Some(vec![1; 32]), "The value should be none" ); } let _ = RocksDB::destroy(&rocksdb::Options::default(), "read_exist_rocks_blob"); } #[test] fn test_read_not_exist() { { let rocksdb = init_rocksdb("read_not_exist_rocks_blob"); assert_eq!( rocksdb.get(&[1; 32]).unwrap().is_none(), true, "The value should be none" ); } let _ = RocksDB::destroy(&rocksdb::Options::default(), "read_not_exist_rocks_blob"); } #[test] fn test_read_error() { /* TO DO: fill, don't know how to make rocksdb return error" */ } #[test] fn test_write() { { let rocksdb = init_rocksdb("write_rocks_blob"); rocksdb.put(&[1; 32], vec![0; 32]).unwrap(); assert_eq!( rocksdb.get(&[1; 32]).unwrap().unwrap(), [0; 32], "The value read was not written or unable to read" ); } let _ = RocksDB::destroy(&rocksdb::Options::default(), "write_rocks_blob"); }