use std::path::Path;
use crate::format::Origin;
pub(crate) fn check(origin: Origin, folder_path: Option<&str>) -> Option<bool> {
match origin {
Origin::Local => Some(Path::new(folder_path?).exists()),
Origin::Cloud | Origin::Stream => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn only_a_local_row_gets_an_answer() {
assert_eq!(check(Origin::Cloud, Some("/contents_1/a.flac")), None);
assert_eq!(check(Origin::Stream, Some("soundcloud:tracks:1")), None);
assert_eq!(check(Origin::Local, None), None);
}
#[test]
fn a_local_path_is_answered_from_the_filesystem() {
let here = concat!(env!("CARGO_MANIFEST_DIR"), "/src/presence.rs");
assert_eq!(check(Origin::Local, Some(here)), Some(true));
assert_eq!(
check(Origin::Local, Some("/nope/definitely/not/here.flac")),
Some(false)
);
}
#[test]
fn another_machines_path_is_missing_not_an_error() {
assert_eq!(
check(Origin::Local, Some("C:/users/someone/Music/a.mp3")),
Some(false)
);
}
}