Moved in new mod file.
This commit is contained in:
parent
d4d42a599e
commit
1f36848450
@ -1,17 +1,34 @@
|
|||||||
use super::{DBError, Database, ErrorCode, FileData, SessionData, Store};
|
mod database;
|
||||||
|
mod error;
|
||||||
|
mod store;
|
||||||
|
|
||||||
use async_std::{
|
use async_std::{
|
||||||
fs::{read, remove_file, write},
|
fs::{read, remove_file, write},
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
use database::Database;
|
||||||
|
use error::{DBError, ErrorCode};
|
||||||
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
use rand::{distributions::Alphanumeric, thread_rng, Rng};
|
||||||
use std::{
|
use std::{
|
||||||
cell::Cell,
|
cell::Cell,
|
||||||
slice, str,
|
slice, str,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
|
use store::Store;
|
||||||
|
|
||||||
const ENTRY: &str = "EntryPoint";
|
const ENTRY: &str = "EntryPoint";
|
||||||
|
|
||||||
|
trait FileData<F> {
|
||||||
|
fn to_bytes(&self) -> Vec<u8>;
|
||||||
|
fn from_bytes(data: &mut slice::Iter<u8>) -> Result<F, DBError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
trait SessionData {
|
||||||
|
fn add(&mut self, key: &str, value: &str, data: &str) -> Result<Vec<String>, DBError>;
|
||||||
|
fn eq(&self, key: &str, value: &str) -> Result<Vec<String>, DBError>;
|
||||||
|
fn list(&self, keys: Vec<&str>) -> Result<Vec<String>, DBError>;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum DataType {
|
enum DataType {
|
||||||
DBMap(Store),
|
DBMap(Store),
|
||||||
@ -192,10 +209,11 @@ impl Entry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Cache;
|
#[derive(Clone)]
|
||||||
|
pub struct MoreThanText;
|
||||||
|
|
||||||
impl Cache {
|
impl MoreThanText {
|
||||||
async fn new<P>(dir: P) -> Result<Self, DBError>
|
pub async fn new<P>(dir: P) -> Result<Self, DBError>
|
||||||
where
|
where
|
||||||
P: Into<PathBuf>,
|
P: Into<PathBuf>,
|
||||||
{
|
{
|
||||||
@ -662,7 +680,9 @@ mod cache {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn create() {
|
async fn create() {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
Cache::new(dir.path().to_str().unwrap()).await.unwrap();
|
MoreThanText::new(dir.path().to_str().unwrap())
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
let epoint = dir.path().join(ENTRY);
|
let epoint = dir.path().join(ENTRY);
|
||||||
assert!(
|
assert!(
|
||||||
epoint.is_file(),
|
epoint.is_file(),
|
||||||
@ -680,7 +700,7 @@ mod cache {
|
|||||||
async fn entry_failure() -> Result<(), DBError> {
|
async fn entry_failure() -> Result<(), DBError> {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let path = dir.path().join("bad").join("path");
|
let path = dir.path().join("bad").join("path");
|
||||||
match Cache::new(path).await {
|
match MoreThanText::new(path).await {
|
||||||
Ok(_) => Err(DBError::new("Should have produced an error.")),
|
Ok(_) => Err(DBError::new("Should have produced an error.")),
|
||||||
Err(err) => match err.code {
|
Err(err) => match err.code {
|
||||||
ErrorCode::CacheReadWrite => {
|
ErrorCode::CacheReadWrite => {
|
||||||
@ -704,7 +724,7 @@ mod cache {
|
|||||||
Entry::new(dir.path().join(ENTRY), data.clone())
|
Entry::new(dir.path().join(ENTRY), data.clone())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let cache = Cache::new(dir.path()).await.unwrap();
|
let cache = MoreThanText::new(dir.path()).await.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
@ -712,7 +732,7 @@ mod cache {
|
|||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let file = dir.path().join(ENTRY);
|
let file = dir.path().join(ENTRY);
|
||||||
write(file, b"Really bad data.").await.unwrap();
|
write(file, b"Really bad data.").await.unwrap();
|
||||||
match Cache::new(dir.path()).await {
|
match MoreThanText::new(dir.path()).await {
|
||||||
Ok(_) => Err(DBError::new("should have errored")),
|
Ok(_) => Err(DBError::new("should have errored")),
|
||||||
Err(_) => Ok(()),
|
Err(_) => Ok(()),
|
||||||
}
|
}
|
||||||
|
0
src/morethantext/session.rs
Normal file
0
src/morethantext/session.rs
Normal file
Loading…
Reference in New Issue
Block a user