use std::fs;
use std::time::Duration;
use crate::prelude::*;
use crate::testing_prelude::*;
use insta::assert_snapshot;
#[tokio::test]
async fn inspect_factory_flac() -> Result<(), TestError> {
let config = AlbumProvider::get_advanced(AlbumConfig::multi_disc()).await;
let path = SAMPLE_SOURCES_DIR.join(config.dir_name());
let factory = InspectFactory::new(false);
let output = factory.create(&path)?;
assert_inspect_snapshot!(output);
Ok(())
}
#[tokio::test]
async fn inspect_factory_320() -> Result<(), TestError> {
let config = AlbumProvider::get_advanced(AlbumConfig::multi_disc()).await;
let transcode = TranscodeProvider::get_advanced(&config, TargetFormat::_320).await;
let path = transcode.transcode_dir();
let factory = InspectFactory::new(false);
let output = factory.create(&path)?;
assert_inspect_snapshot!(output);
Ok(())
}
#[tokio::test]
async fn inspect_factory_v0() -> Result<(), TestError> {
let config = AlbumProvider::get_advanced(AlbumConfig::multi_disc()).await;
let transcode = TranscodeProvider::get_advanced(&config, TargetFormat::V0).await;
let path = transcode.transcode_dir();
let factory = InspectFactory::new(false);
let output = factory.create(&path)?;
assert_inspect_snapshot!(output);
Ok(())
}
#[tokio::test]
async fn inspect_factory_flac_48khz() -> Result<(), TestError> {
let config = AlbumProvider::get(SampleFormat::FLAC16_48).await;
let path = SAMPLE_SOURCES_DIR.join(config.dir_name());
let factory = InspectFactory::new(false);
let output = factory.create(&path)?;
assert_inspect_snapshot!(output);
Ok(())
}
#[tokio::test]
#[expect(
clippy::indexing_slicing,
reason = "test with controlled config guarantees indices exist"
)]
async fn inspect_factory_mixed() -> Result<(), TestError> {
let config = AlbumProvider::get_advanced(AlbumConfig::multi_disc()).await;
let flac_dir = SAMPLE_SOURCES_DIR.join(config.dir_name());
let transcode = TranscodeProvider::get_advanced(&config, TargetFormat::_320).await;
let mp3_dir = transcode.transcode_dir();
let temp = TempDirectory::create("mixed_format");
fs::copy(
flac_dir
.join("Disc 1")
.join(config.track_filename(&config.tracks[0])),
temp.join(config.track_filename(&config.tracks[0])),
)?;
let mp3_filename = config
.track_filename(&config.tracks[1])
.replace(".flac", ".mp3");
fs::copy(
mp3_dir.join("Disc 1").join(&mp3_filename),
temp.join(&mp3_filename),
)?;
let factory = InspectFactory::new(false);
let output = factory.create(&temp)?;
assert_inspect_snapshot!(output);
Ok(())
}
#[test]
fn inspect_factory_properties_table_mixed_formats() {
let factory = InspectFactory::new(false);
let tracks = vec![
TrackInfo {
track: Some("1".to_owned()),
duration: Duration::from_secs(312),
file_size: 30_408_704,
bit_rate: 780,
..TrackInfo::mock_flac()
},
TrackInfo {
track: Some("2".to_owned()),
duration: Duration::from_secs(245),
file_size: 47_710_208,
bit_rate: 1558,
sample_rate: 96000,
bit_depth: Some(24),
..TrackInfo::mock_flac()
},
TrackInfo {
track: Some("3".to_owned()),
duration: Duration::from_secs(198),
file_size: 19_922_944,
bit_rate: 805,
sample_rate: 48000,
bit_depth: Some(24),
..TrackInfo::mock_flac()
},
TrackInfo {
track: Some("4".to_owned()),
duration: Duration::from_secs(312),
file_size: 12_288_000,
..TrackInfo::mock_mp3()
},
TrackInfo {
track: Some("5".to_owned()),
duration: Duration::from_secs(312),
file_size: 9_523_200,
bit_rate: 245,
sample_rate: 48000,
..TrackInfo::mock_mp3()
},
];
let output = factory.format_properties_table(&tracks);
assert_snapshot!(output);
}