Add ProcessingJob type with source management and output path resolution
All 6 pipeline tests passing.
This commit is contained in:
61
pixstrip-core/tests/pipeline_tests.rs
Normal file
61
pixstrip-core/tests/pipeline_tests.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use pixstrip_core::pipeline::*;
|
||||
use pixstrip_core::operations::*;
|
||||
use pixstrip_core::types::*;
|
||||
|
||||
#[test]
|
||||
fn processing_job_default_has_no_operations() {
|
||||
let job = ProcessingJob::new("/tmp/input/", "/tmp/output/");
|
||||
assert!(job.resize.is_none());
|
||||
assert!(job.convert.is_none());
|
||||
assert!(job.compress.is_none());
|
||||
assert!(job.metadata.is_none());
|
||||
assert!(job.watermark.is_none());
|
||||
assert!(job.rename.is_none());
|
||||
assert!(job.sources.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn processing_job_add_sources() {
|
||||
let mut job = ProcessingJob::new("/tmp/input/", "/tmp/output/");
|
||||
job.add_source("/tmp/input/photo.jpg");
|
||||
job.add_source("/tmp/input/image.png");
|
||||
assert_eq!(job.sources.len(), 2);
|
||||
assert_eq!(job.sources[0].original_format, Some(ImageFormat::Jpeg));
|
||||
assert_eq!(job.sources[1].original_format, Some(ImageFormat::Png));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn processing_job_with_resize() {
|
||||
let mut job = ProcessingJob::new("/tmp/input/", "/tmp/output/");
|
||||
job.resize = Some(ResizeConfig::ByWidth(1200));
|
||||
assert!(job.resize.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn processing_job_operation_count() {
|
||||
let mut job = ProcessingJob::new("/tmp/input/", "/tmp/output/");
|
||||
assert_eq!(job.operation_count(), 0);
|
||||
job.resize = Some(ResizeConfig::ByWidth(1200));
|
||||
assert_eq!(job.operation_count(), 1);
|
||||
job.compress = Some(CompressConfig::Preset(QualityPreset::High));
|
||||
assert_eq!(job.operation_count(), 2);
|
||||
job.metadata = Some(MetadataConfig::StripAll);
|
||||
assert_eq!(job.operation_count(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn processing_job_output_path() {
|
||||
let job = ProcessingJob::new("/tmp/input/", "/tmp/output/");
|
||||
let source = ImageSource::from_path("/tmp/input/photo.jpg");
|
||||
let output = job.output_path_for(&source, None);
|
||||
assert_eq!(output.to_str().unwrap(), "/tmp/output/photo.jpg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn processing_job_output_path_with_format_change() {
|
||||
let mut job = ProcessingJob::new("/tmp/input/", "/tmp/output/");
|
||||
job.convert = Some(ConvertConfig::SingleFormat(ImageFormat::WebP));
|
||||
let source = ImageSource::from_path("/tmp/input/photo.jpg");
|
||||
let output = job.output_path_for(&source, Some(ImageFormat::WebP));
|
||||
assert_eq!(output.to_str().unwrap(), "/tmp/output/photo.webp");
|
||||
}
|
||||
Reference in New Issue
Block a user