Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
117
crates/adapters/assets/tests/config_path.rs
Normal file
117
crates/adapters/assets/tests/config_path.rs
Normal file
@@ -0,0 +1,117 @@
|
||||
mod common;
|
||||
|
||||
use assets::{Platform, config_path};
|
||||
use common::{env_of, path};
|
||||
|
||||
#[test]
|
||||
fn xdg_prefers_config_home() {
|
||||
let env = env_of(&[("XDG_CONFIG_HOME", "/xdg"), ("HOME", "/home/user")]);
|
||||
|
||||
assert_eq!(
|
||||
config_path(Platform::Xdg, env),
|
||||
path("/xdg/dvd-thing/logo.png")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xdg_falls_back_to_home_dot_config() {
|
||||
let env = env_of(&[("HOME", "/home/user")]);
|
||||
|
||||
assert_eq!(
|
||||
config_path(Platform::Xdg, env),
|
||||
path("/home/user/.config/dvd-thing/logo.png")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn xdg_ignores_a_relative_config_home() {
|
||||
let env = env_of(&[("XDG_CONFIG_HOME", "relative/dir"), ("HOME", "/home/user")]);
|
||||
|
||||
assert_eq!(
|
||||
config_path(Platform::Xdg, env),
|
||||
path("/home/user/.config/dvd-thing/logo.png")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macos_uses_application_support() {
|
||||
let env = env_of(&[("HOME", "/Users/gabriel")]);
|
||||
|
||||
assert_eq!(
|
||||
config_path(Platform::MacOs, env),
|
||||
path("/Users/gabriel/Library/Application Support/dvd-thing/logo.png")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn macos_still_honours_an_explicit_xdg_config_home() {
|
||||
let env = env_of(&[("XDG_CONFIG_HOME", "/Users/gabriel/.config")]);
|
||||
|
||||
assert_eq!(
|
||||
config_path(Platform::MacOs, env),
|
||||
path("/Users/gabriel/.config/dvd-thing/logo.png")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_prefers_appdata() {
|
||||
let env = env_of(&[
|
||||
("APPDATA", r"C:\Users\gabriel\AppData\Roaming"),
|
||||
("USERPROFILE", r"C:\Users\gabriel"),
|
||||
]);
|
||||
|
||||
assert_eq!(
|
||||
config_path(Platform::Windows, env),
|
||||
path(r"C:\Users\gabriel\AppData\Roaming/dvd-thing/logo.png")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_falls_back_to_user_profile() {
|
||||
let env = env_of(&[("USERPROFILE", r"C:\Users\gabriel")]);
|
||||
|
||||
assert_eq!(
|
||||
config_path(Platform::Windows, env),
|
||||
path(r"C:\Users\gabriel/AppData/Roaming/dvd-thing/logo.png")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn windows_ignores_unix_variables() {
|
||||
let env = env_of(&[("HOME", "/home/user"), ("XDG_CONFIG_HOME", "/xdg")]);
|
||||
|
||||
assert_eq!(config_path(Platform::Windows, env), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_environment_yields_no_path() {
|
||||
for platform in [Platform::Xdg, Platform::MacOs, Platform::Windows] {
|
||||
assert_eq!(config_path(platform, env_of(&[])), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_variable_counts_as_unset() {
|
||||
let env = env_of(&[("XDG_CONFIG_HOME", ""), ("HOME", "/home/user")]);
|
||||
|
||||
assert_eq!(
|
||||
config_path(Platform::Xdg, env),
|
||||
path("/home/user/.config/dvd-thing/logo.png")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_home_does_not_produce_a_relative_path() {
|
||||
assert_eq!(config_path(Platform::Xdg, env_of(&[("HOME", "")])), None);
|
||||
assert_eq!(config_path(Platform::MacOs, env_of(&[("HOME", "")])), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_appdata_falls_back_to_user_profile() {
|
||||
let env = env_of(&[("APPDATA", ""), ("USERPROFILE", r"C:\Users\gabriel")]);
|
||||
|
||||
assert_eq!(
|
||||
config_path(Platform::Windows, env),
|
||||
path(r"C:\Users\gabriel/AppData/Roaming/dvd-thing/logo.png")
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user