style: cargo fmt --all

This commit is contained in:
2026-05-31 05:31:42 +02:00
parent 4b31a0f74b
commit c2ebca0da0
138 changed files with 2422 additions and 1164 deletions

View File

@@ -1,20 +1,18 @@
use std::sync::Arc;
use bytes::Bytes;
use application::testing::{
InMemoryAssetRepository, InMemoryIngestSessionRepository,
InMemoryLibraryPathRepository, InMemoryQuotaRepository,
InMemoryStorageVolumeRepository, InMemoryUsageLedgerRepository,
InMemoryFileStorage, StubEventPublisher,
};
use application::storage::{
IngestAssetCommand, IngestAssetHandler,
IngestAssetCommand, IngestAssetHandler, RegisterLibraryPathCommand, RegisterLibraryPathHandler,
RegisterVolumeCommand, RegisterVolumeHandler,
RegisterLibraryPathCommand, RegisterLibraryPathHandler,
};
use application::testing::{
InMemoryAssetRepository, InMemoryFileStorage, InMemoryIngestSessionRepository,
InMemoryLibraryPathRepository, InMemoryQuotaRepository, InMemoryStorageVolumeRepository,
InMemoryUsageLedgerRepository, StubEventPublisher,
};
use bytes::Bytes;
use domain::entities::{IngestStatus, QuotaDefinition, TimePeriod, UsageType};
use domain::errors::DomainError;
use domain::ports::QuotaRepository;
use domain::value_objects::SystemId;
use std::sync::Arc;
struct Harness {
ingest_repo: Arc<InMemoryIngestSessionRepository>,
@@ -55,19 +53,26 @@ impl Harness {
async fn setup_volume_and_path(&self, owner: SystemId) -> SystemId {
let vol_handler = RegisterVolumeHandler::new(self.vol_repo.clone());
let vol = vol_handler.execute(RegisterVolumeCommand {
volume_name: "main".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
}).await.unwrap();
let vol = vol_handler
.execute(RegisterVolumeCommand {
volume_name: "main".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
})
.await
.unwrap();
let path_handler = RegisterLibraryPathHandler::new(self.vol_repo.clone(), self.path_repo.clone());
let path = path_handler.execute(RegisterLibraryPathCommand {
volume_id: vol.volume_id,
relative_path: "photos/inbox".into(),
owner_id: owner,
is_ingest_destination: true,
}).await.unwrap();
let path_handler =
RegisterLibraryPathHandler::new(self.vol_repo.clone(), self.path_repo.clone());
let path = path_handler
.execute(RegisterLibraryPathCommand {
volume_id: vol.volume_id,
relative_path: "photos/inbox".into(),
owner_id: owner,
is_ingest_destination: true,
})
.await
.unwrap();
path.path_id
}
}
@@ -83,15 +88,18 @@ async fn ingests_successfully() {
let path_id = h.setup_volume_and_path(user).await;
let handler = h.ingest_handler();
let (asset, session) = handler.execute(IngestAssetCommand {
uploader_id: user,
client_device_id: "iphone-1".into(),
filename: "photo.jpg".into(),
checksum: valid_checksum(),
target_path_id: path_id,
file_size: 1024,
data: Bytes::from(vec![0u8; 1024]),
}).await.unwrap();
let (asset, session) = handler
.execute(IngestAssetCommand {
uploader_id: user,
client_device_id: "iphone-1".into(),
filename: "photo.jpg".into(),
checksum: valid_checksum(),
target_path_id: path_id,
file_size: 1024,
data: Bytes::from(vec![0u8; 1024]),
})
.await
.unwrap();
assert_eq!(asset.mime_type, "image/jpeg");
assert_eq!(asset.file_size, 1024);
@@ -111,15 +119,17 @@ async fn rejects_quota_exceeded() {
h.quota_repo.save(&quota).await.unwrap();
let handler = h.ingest_handler();
let result = handler.execute(IngestAssetCommand {
uploader_id: user,
client_device_id: "iphone-1".into(),
filename: "big.jpg".into(),
checksum: valid_checksum(),
target_path_id: path_id,
file_size: 1024,
data: Bytes::from(vec![0u8; 1024]),
}).await;
let result = handler
.execute(IngestAssetCommand {
uploader_id: user,
client_device_id: "iphone-1".into(),
filename: "big.jpg".into(),
checksum: valid_checksum(),
target_path_id: path_id,
file_size: 1024,
data: Bytes::from(vec![0u8; 1024]),
})
.await;
assert!(matches!(result, Err(DomainError::QuotaExceeded(_))));
}
@@ -131,15 +141,17 @@ async fn rejects_invalid_checksum() {
let path_id = h.setup_volume_and_path(user).await;
let handler = h.ingest_handler();
let result = handler.execute(IngestAssetCommand {
uploader_id: user,
client_device_id: "iphone-1".into(),
filename: "photo.jpg".into(),
checksum: "tooshort".into(),
target_path_id: path_id,
file_size: 1024,
data: Bytes::from(vec![0u8; 1024]),
}).await;
let result = handler
.execute(IngestAssetCommand {
uploader_id: user,
client_device_id: "iphone-1".into(),
filename: "photo.jpg".into(),
checksum: "tooshort".into(),
target_path_id: path_id,
file_size: 1024,
data: Bytes::from(vec![0u8; 1024]),
})
.await;
assert!(matches!(result, Err(DomainError::Validation(_))));
}
@@ -151,11 +163,14 @@ async fn rejects_non_ingest_path() {
// Create volume + non-ingest path directly
let vol_handler = RegisterVolumeHandler::new(h.vol_repo.clone());
let vol = vol_handler.execute(RegisterVolumeCommand {
volume_name: "main".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
}).await.unwrap();
let vol = vol_handler
.execute(RegisterVolumeCommand {
volume_name: "main".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
})
.await
.unwrap();
let path = domain::entities::LibraryPath::new_user_owned(
vol.volume_id,
@@ -167,15 +182,17 @@ async fn rejects_non_ingest_path() {
h.path_repo.save(&path).await.unwrap();
let handler = h.ingest_handler();
let result = handler.execute(IngestAssetCommand {
uploader_id: user,
client_device_id: "iphone-1".into(),
filename: "photo.jpg".into(),
checksum: valid_checksum(),
target_path_id: path.path_id,
file_size: 1024,
data: Bytes::from(vec![0u8; 1024]),
}).await;
let result = handler
.execute(IngestAssetCommand {
uploader_id: user,
client_device_id: "iphone-1".into(),
filename: "photo.jpg".into(),
checksum: valid_checksum(),
target_path_id: path.path_id,
file_size: 1024,
data: Bytes::from(vec![0u8; 1024]),
})
.await;
assert!(matches!(result, Err(DomainError::Validation(_))));
}

View File

@@ -1,3 +1,3 @@
mod register_volume;
mod register_library_path;
mod ingest_asset;
mod register_library_path;
mod register_volume;

View File

@@ -1,8 +1,11 @@
use std::sync::Arc;
use application::testing::{InMemoryStorageVolumeRepository, InMemoryLibraryPathRepository};
use application::storage::{RegisterVolumeCommand, RegisterVolumeHandler, RegisterLibraryPathCommand, RegisterLibraryPathHandler};
use application::storage::{
RegisterLibraryPathCommand, RegisterLibraryPathHandler, RegisterVolumeCommand,
RegisterVolumeHandler,
};
use application::testing::{InMemoryLibraryPathRepository, InMemoryStorageVolumeRepository};
use domain::errors::DomainError;
use domain::value_objects::SystemId;
use std::sync::Arc;
#[tokio::test]
async fn creates_path() {
@@ -10,20 +13,26 @@ async fn creates_path() {
let path_repo = Arc::new(InMemoryLibraryPathRepository::new());
let vol_handler = RegisterVolumeHandler::new(vol_repo.clone());
let vol = vol_handler.execute(RegisterVolumeCommand {
volume_name: "main".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
}).await.unwrap();
let vol = vol_handler
.execute(RegisterVolumeCommand {
volume_name: "main".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
})
.await
.unwrap();
let handler = RegisterLibraryPathHandler::new(vol_repo, path_repo);
let owner = SystemId::new();
let path = handler.execute(RegisterLibraryPathCommand {
volume_id: vol.volume_id,
relative_path: "photos/inbox".into(),
owner_id: owner,
is_ingest_destination: true,
}).await.unwrap();
let path = handler
.execute(RegisterLibraryPathCommand {
volume_id: vol.volume_id,
relative_path: "photos/inbox".into(),
owner_id: owner,
is_ingest_destination: true,
})
.await
.unwrap();
assert_eq!(path.volume_id, vol.volume_id);
assert_eq!(path.relative_path, "photos/inbox");
@@ -37,11 +46,13 @@ async fn rejects_nonexistent_volume() {
let path_repo = Arc::new(InMemoryLibraryPathRepository::new());
let handler = RegisterLibraryPathHandler::new(vol_repo, path_repo);
let result = handler.execute(RegisterLibraryPathCommand {
volume_id: SystemId::new(),
relative_path: "photos/inbox".into(),
owner_id: SystemId::new(),
is_ingest_destination: true,
}).await;
let result = handler
.execute(RegisterLibraryPathCommand {
volume_id: SystemId::new(),
relative_path: "photos/inbox".into(),
owner_id: SystemId::new(),
is_ingest_destination: true,
})
.await;
assert!(matches!(result, Err(DomainError::NotFound(_))));
}

View File

@@ -1,17 +1,20 @@
use std::sync::Arc;
use application::testing::InMemoryStorageVolumeRepository;
use application::storage::{RegisterVolumeCommand, RegisterVolumeHandler};
use application::testing::InMemoryStorageVolumeRepository;
use domain::errors::DomainError;
use std::sync::Arc;
#[tokio::test]
async fn creates_volume() {
let repo = Arc::new(InMemoryStorageVolumeRepository::new());
let handler = RegisterVolumeHandler::new(repo);
let vol = handler.execute(RegisterVolumeCommand {
volume_name: "primary".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
}).await.unwrap();
let vol = handler
.execute(RegisterVolumeCommand {
volume_name: "primary".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
})
.await
.unwrap();
assert_eq!(vol.volume_name, "primary");
assert_eq!(vol.uri_prefix, "file:///data");
assert!(vol.is_writable);
@@ -21,10 +24,12 @@ async fn creates_volume() {
async fn rejects_empty_name() {
let repo = Arc::new(InMemoryStorageVolumeRepository::new());
let handler = RegisterVolumeHandler::new(repo);
let result = handler.execute(RegisterVolumeCommand {
volume_name: "".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
}).await;
let result = handler
.execute(RegisterVolumeCommand {
volume_name: "".into(),
uri_prefix: "file:///data".into(),
is_writable: true,
})
.await;
assert!(matches!(result, Err(DomainError::Validation(_))));
}

View File

@@ -1,9 +1,9 @@
use std::sync::Arc;
use application::storage::{CheckQuotaHandler, CheckQuotaQuery};
use application::testing::{InMemoryQuotaRepository, InMemoryUsageLedgerRepository};
use application::storage::{CheckQuotaQuery, CheckQuotaHandler};
use domain::entities::{QuotaDefinition, TimePeriod, UsageLedgerEntry, UsageType};
use domain::ports::UsageLedgerRepository;
use domain::value_objects::SystemId;
use std::sync::Arc;
#[tokio::test]
async fn returns_allowed() {
@@ -17,11 +17,14 @@ async fn returns_allowed() {
quota_repo.save(&quota).await.unwrap();
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
let result = handler.execute(CheckQuotaQuery {
user_id: user,
usage_type: UsageType::StorageBytes,
requested_amount: 5_000,
}).await.unwrap();
let result = handler
.execute(CheckQuotaQuery {
user_id: user,
usage_type: UsageType::StorageBytes,
requested_amount: 5_000,
})
.await
.unwrap();
assert!(result.allowed);
assert_eq!(result.limit, 10_000);
@@ -44,11 +47,14 @@ async fn returns_denied() {
ledger_repo.record(&entry).await.unwrap();
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
let result = handler.execute(CheckQuotaQuery {
user_id: user,
usage_type: UsageType::StorageBytes,
requested_amount: 200,
}).await.unwrap();
let result = handler
.execute(CheckQuotaQuery {
user_id: user,
usage_type: UsageType::StorageBytes,
requested_amount: 200,
})
.await
.unwrap();
assert!(!result.allowed);
assert_eq!(result.current_usage, 900);
@@ -60,11 +66,14 @@ async fn returns_unlimited_when_no_quota() {
let ledger_repo = Arc::new(InMemoryUsageLedgerRepository::new());
let handler = CheckQuotaHandler::new(quota_repo, ledger_repo);
let result = handler.execute(CheckQuotaQuery {
user_id: SystemId::new(),
usage_type: UsageType::StorageBytes,
requested_amount: 999_999,
}).await.unwrap();
let result = handler
.execute(CheckQuotaQuery {
user_id: SystemId::new(),
usage_type: UsageType::StorageBytes,
requested_amount: 999_999,
})
.await
.unwrap();
assert!(result.allowed);
assert!(result.is_unlimited);