mod common; use application::LogoSourcePort; use assets::{FileLogoSource, Platform}; use common::{LOGO_BYTES, env_of, scratch, write_logo}; #[test] fn reads_an_explicit_path() { let logo = write_logo(&scratch("explicit")); let source = FileLogoSource::new(Some(logo), None).unwrap(); assert_eq!(source.load().unwrap(), Some(LOGO_BYTES)); } #[test] fn a_missing_explicit_path_is_an_error() { let missing = scratch("explicit-missing").join("absent.png"); let error = FileLogoSource::new(Some(missing), None).unwrap_err(); assert!(error.to_string().contains("DVD_LOGO")); } #[test] fn an_explicit_path_wins_over_the_configured_one() { let directory = scratch("explicit-wins"); let explicit = directory.join("chosen.png"); std::fs::write(&explicit, b"chosen").unwrap(); let source = FileLogoSource::new(Some(explicit), Some(write_logo(&directory))).unwrap(); assert_eq!(source.load().unwrap(), Some(b"chosen".as_slice())); } #[test] fn reads_the_configured_path() { let logo = write_logo(&scratch("configured")); let source = FileLogoSource::new(None, Some(logo)).unwrap(); assert_eq!(source.load().unwrap(), Some(LOGO_BYTES)); } #[test] fn a_missing_configured_path_is_not_an_error() { let missing = scratch("configured-missing").join("absent.png"); let source = FileLogoSource::new(None, Some(missing)).unwrap(); assert_eq!(source.load().unwrap(), None); } #[test] fn no_paths_at_all_yields_nothing() { let source = FileLogoSource::new(None, None).unwrap(); assert_eq!(source.load().unwrap(), None); } #[test] fn an_unreadable_configured_path_is_an_error() { let directory = scratch("configured-unreadable"); std::fs::create_dir_all(directory.join("logo.png")).unwrap(); assert!(FileLogoSource::new(None, Some(directory.join("logo.png"))).is_err()); } #[test] fn an_empty_dvd_logo_variable_is_treated_as_unset() { let env = env_of(&[("DVD_LOGO", ""), ("HOME", "")]); let source = FileLogoSource::from_environment(Platform::Xdg, &env).unwrap(); assert_eq!(source.load().unwrap(), None); } #[test] fn a_set_dvd_logo_variable_still_wins() { let logo = write_logo(&scratch("env-explicit")); let env = env_of(&[("DVD_LOGO", logo.to_str().unwrap()), ("HOME", "")]); let source = FileLogoSource::from_environment(Platform::Xdg, &env).unwrap(); assert_eq!(source.load().unwrap(), Some(LOGO_BYTES)); }