test: move small adapter tests to tests/
event-publisher, export, rss, media-server, object-storage, nats(config).
Kept inline (private fn, no public path): nats src/subject.rs
tests::{review_logged_subject,review_updated_subject,movie_discovered_subject,
consumer_subject_filter_appends_wildcard} - event_to_subject/consumer_subject_filter private.
object-storage build_local_store tests rewritten via StorageConfig::from_config.
This commit is contained in:
@@ -84,7 +84,3 @@ pub fn create_event_channel(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[path = "tests/lib.rs"]
|
|
||||||
mod tests;
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
use super::*;
|
use domain::ports::{EventConsumer, EventPublisher};
|
||||||
use domain::{
|
use domain::{
|
||||||
events::DomainEvent,
|
events::DomainEvent,
|
||||||
value_objects::{ExternalMetadataId, MovieId},
|
value_objects::{ExternalMetadataId, MovieId},
|
||||||
};
|
};
|
||||||
|
use event_publisher::{EventPublisherConfig, create_event_channel};
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
|
||||||
fn movie_discovered() -> DomainEvent {
|
fn movie_discovered() -> DomainEvent {
|
||||||
@@ -107,7 +107,3 @@ fn entry_to_json(e: &DiaryEntry) -> serde_json::Value {
|
|||||||
"spoilers": e.review().spoilers(),
|
"spoilers": e.review().spoilers(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[path = "tests/lib.rs"]
|
|
||||||
mod tests;
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use super::ExportAdapter;
|
|
||||||
use domain::{
|
use domain::{
|
||||||
models::{DiaryEntry, ExportFormat, Movie, ReviewEdit},
|
models::{DiaryEntry, ExportFormat, Movie, ReviewEdit},
|
||||||
ports::DiaryExporter,
|
ports::DiaryExporter,
|
||||||
@@ -7,6 +6,7 @@ use domain::{
|
|||||||
},
|
},
|
||||||
value_objects::{Comment, ExternalMetadataId, UserId},
|
value_objects::{Comment, ExternalMetadataId, UserId},
|
||||||
};
|
};
|
||||||
|
use export::ExportAdapter;
|
||||||
|
|
||||||
async fn collect_stream(
|
async fn collect_stream(
|
||||||
stream: futures::stream::BoxStream<'static, Result<bytes::Bytes, domain::errors::DomainError>>,
|
stream: futures::stream::BoxStream<'static, Result<bytes::Bytes, domain::errors::DomainError>>,
|
||||||
@@ -58,7 +58,3 @@ struct JellyfinPayload {
|
|||||||
#[serde(rename = "Provider_imdb")]
|
#[serde(rename = "Provider_imdb")]
|
||||||
provider_imdb: Option<String>,
|
provider_imdb: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[path = "tests/jellyfin.rs"]
|
|
||||||
mod tests;
|
|
||||||
|
|||||||
@@ -68,7 +68,3 @@ struct PlexMetadata {
|
|||||||
struct PlexGuid {
|
struct PlexGuid {
|
||||||
id: String,
|
id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[path = "tests/plex.rs"]
|
|
||||||
mod tests;
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::*;
|
use domain::ports::MediaServerParser;
|
||||||
|
use media_server::JellyfinParser;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parses_valid_playback_stop() {
|
fn parses_valid_playback_stop() {
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
use super::*;
|
use domain::ports::MediaServerParser;
|
||||||
|
use media_server::PlexParser;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parses_movie_scrobble() {
|
fn parses_movie_scrobble() {
|
||||||
@@ -35,7 +35,3 @@ impl NatsConfig {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[path = "tests/config.rs"]
|
|
||||||
mod tests;
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use super::*;
|
use nats::{NatsConfig, NatsMode};
|
||||||
|
|
||||||
fn section(url: Option<&str>, mode: &str) -> ::config::NatsConfig {
|
fn section(url: Option<&str>, mode: &str) -> config::NatsConfig {
|
||||||
::config::NatsConfig {
|
config::NatsConfig {
|
||||||
url: url.map(str::to_owned),
|
url: url.map(str::to_owned),
|
||||||
mode: mode.into(),
|
mode: mode.into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
@@ -10,12 +10,12 @@ fn section(url: Option<&str>, mode: &str) -> ::config::NatsConfig {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn errors_without_nats_url() {
|
fn errors_without_nats_url() {
|
||||||
assert!(NatsConfig::from_config(&::config::NatsConfig::default()).is_err());
|
assert!(NatsConfig::from_config(&config::NatsConfig::default()).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn defaults_with_only_url() {
|
fn defaults_with_only_url() {
|
||||||
let cfg = NatsConfig::from_config(&::config::NatsConfig {
|
let cfg = NatsConfig::from_config(&config::NatsConfig {
|
||||||
url: Some("nats://localhost:4222".into()),
|
url: Some("nats://localhost:4222".into()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
@@ -62,7 +62,3 @@ fn build_local_store(path: &str) -> anyhow::Result<Arc<dyn ObjectStore>> {
|
|||||||
.context("Failed to initialise local file system store")?;
|
.context("Failed to initialise local file system store")?;
|
||||||
Ok(Arc::new(store))
|
Ok(Arc::new(store))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[path = "tests/config.rs"]
|
|
||||||
mod tests;
|
|
||||||
|
|||||||
@@ -132,7 +132,3 @@ pub fn create(config: &::config::StorageConfig) -> anyhow::Result<Arc<dyn Object
|
|||||||
StorageConfig::from_config(config)?,
|
StorageConfig::from_config(config)?,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[path = "tests/lib.rs"]
|
|
||||||
mod tests;
|
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
use super::*;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use domain::{
|
||||||
|
errors::DomainError,
|
||||||
|
ports::{EventHandler, ObjectStorage},
|
||||||
|
};
|
||||||
|
use object_storage::{ImageCleanupHandler, ObjectStorageAdapter};
|
||||||
use object_store::memory::InMemory;
|
use object_store::memory::InMemory;
|
||||||
|
|
||||||
fn adapter() -> ObjectStorageAdapter {
|
fn adapter() -> ObjectStorageAdapter {
|
||||||
@@ -1,9 +1,17 @@
|
|||||||
use super::*;
|
use object_storage::StorageConfig;
|
||||||
|
|
||||||
|
fn local_section(dir: &std::path::Path) -> config::StorageConfig {
|
||||||
|
config::StorageConfig {
|
||||||
|
backend: "local".into(),
|
||||||
|
path: dir.to_str().unwrap().into(),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn local_store_creates_dir_and_succeeds() {
|
fn local_store_creates_dir_and_succeeds() {
|
||||||
let dir = std::env::temp_dir().join(format!("image_test_{}", uuid::Uuid::new_v4()));
|
let dir = std::env::temp_dir().join(format!("image_test_{}", uuid::Uuid::new_v4()));
|
||||||
let result = build_local_store(dir.to_str().unwrap());
|
let result = StorageConfig::from_config(&local_section(&dir));
|
||||||
assert!(result.is_ok(), "expected Ok, got: {:?}", result.err());
|
assert!(result.is_ok(), "expected Ok, got: {:?}", result.err());
|
||||||
assert!(dir.exists(), "directory should have been created");
|
assert!(dir.exists(), "directory should have been created");
|
||||||
}
|
}
|
||||||
@@ -12,13 +20,13 @@ fn local_store_creates_dir_and_succeeds() {
|
|||||||
fn local_store_succeeds_if_dir_already_exists() {
|
fn local_store_succeeds_if_dir_already_exists() {
|
||||||
let dir = std::env::temp_dir().join(format!("image_test_{}", uuid::Uuid::new_v4()));
|
let dir = std::env::temp_dir().join(format!("image_test_{}", uuid::Uuid::new_v4()));
|
||||||
std::fs::create_dir_all(&dir).unwrap();
|
std::fs::create_dir_all(&dir).unwrap();
|
||||||
let result = build_local_store(dir.to_str().unwrap());
|
let result = StorageConfig::from_config(&local_section(&dir));
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn s3_backend_requires_endpoint() {
|
fn s3_backend_requires_endpoint() {
|
||||||
let section = ::config::StorageConfig {
|
let section = config::StorageConfig {
|
||||||
backend: "s3".into(),
|
backend: "s3".into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -28,7 +36,7 @@ fn s3_backend_requires_endpoint() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unknown_backend_is_error() {
|
fn unknown_backend_is_error() {
|
||||||
let section = ::config::StorageConfig {
|
let section = config::StorageConfig {
|
||||||
backend: "ftp".into(),
|
backend: "ftp".into(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
@@ -88,7 +88,3 @@ impl RssFeedRenderer for RssAdapter {
|
|||||||
Ok(channel.to_string())
|
Ok(channel.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
#[path = "tests/lib.rs"]
|
|
||||||
mod tests;
|
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
use super::*;
|
use domain::models::DiaryEntry;
|
||||||
use domain::models::ReviewEdit;
|
use domain::models::ReviewEdit;
|
||||||
|
use domain::ports::{FeedChannel, RssFeedRenderer};
|
||||||
use domain::testing::{test_movie_with_year, test_review};
|
use domain::testing::{test_movie_with_year, test_review};
|
||||||
use domain::value_objects::{Comment, UserId};
|
use domain::value_objects::{Comment, UserId};
|
||||||
|
use rss::RssAdapter;
|
||||||
|
|
||||||
fn channel<'a>(title: &'a str) -> FeedChannel<'a> {
|
fn channel<'a>(title: &'a str) -> FeedChannel<'a> {
|
||||||
FeedChannel {
|
FeedChannel {
|
||||||
Reference in New Issue
Block a user