use std::path::Path;
use async_trait::async_trait;
use bytes::Bytes;
use super::{GetResponse, ListEntry, StorageResult, StoreDriver, UploadResponse};
use crate::storage::StorageError;
pub struct NullStorage {}
#[must_use]
pub fn new() -> Box<dyn StoreDriver> {
Box::new(NullStorage {})
}
#[async_trait]
impl StoreDriver for NullStorage {
async fn upload(&self, _path: &Path, _content: &Bytes) -> StorageResult<UploadResponse> {
Err(StorageError::Any(
"Operation not supported by null storage".into(),
))
}
async fn get(&self, _path: &Path) -> StorageResult<GetResponse> {
Err(StorageError::Any(
"Operation not supported by null storage".into(),
))
}
async fn delete(&self, _path: &Path) -> StorageResult<()> {
Err(StorageError::Any(
"Operation not supported by null storage".into(),
))
}
async fn rename(&self, _from: &Path, _to: &Path) -> StorageResult<()> {
Err(StorageError::Any(
"Operation not supported by null storage".into(),
))
}
async fn copy(&self, _from: &Path, _to: &Path) -> StorageResult<()> {
Err(StorageError::Any(
"Operation not supported by null storage".into(),
))
}
async fn exists(&self, _path: &Path) -> StorageResult<bool> {
Err(StorageError::Any(
"Operation not supported by null storage".into(),
))
}
async fn list(&self, _path: &Path, _recursive: bool) -> StorageResult<Vec<ListEntry>> {
Err(StorageError::Any(
"Operation not supported by null storage".into(),
))
}
async fn stat(&self, _path: &Path) -> StorageResult<ListEntry> {
Err(StorageError::Any(
"Operation not supported by null storage".into(),
))
}
}
#[cfg(test)]
mod tests {
use std::path::Path;
use super::new;
#[tokio::test]
async fn every_read_refuses_rather_than_reporting_emptiness() {
let store = new();
let path = Path::new("anything.txt");
assert!(store.exists(path).await.is_err());
assert!(store.list(path, true).await.is_err());
assert!(store.list(path, false).await.is_err());
assert!(store.stat(path).await.is_err());
}
}