keysources: label() on keydb/online sources; neutral path in the XDG test

This commit is contained in:
Matthew Jackson
2026-06-23 09:09:06 -07:00
parent 7982d16225
commit a287e165bd
3 changed files with 13 additions and 5 deletions
+4
View File
@@ -121,6 +121,10 @@ impl KeySource for KeydbSource {
true true
} }
fn label(&self) -> &'static str {
"keydb"
}
fn next_key(&mut self, inputs: &DiscInputs) -> Option<Key> { fn next_key(&mut self, inputs: &DiscInputs) -> Option<Key> {
// On the first ask, parse the keydb once and build the ordered candidate // On the first ask, parse the keydb once and build the ordered candidate
// list; later asks just advance the cursor. A missing/unreadable keydb // list; later asks just advance the cursor. A missing/unreadable keydb
+4
View File
@@ -319,6 +319,10 @@ impl KeySource for OnlineSource {
true true
} }
fn label(&self) -> &'static str {
"online"
}
fn errored(&self) -> bool { fn errored(&self) -> bool {
self.errored self.errored
} }
+5 -5
View File
@@ -183,13 +183,13 @@ mod tests {
#[test] #[test]
fn unix_default_is_home_dotconfig() { fn unix_default_is_home_dotconfig() {
with_env( with_env(
&[("HOME", Some("/home/matt")), ("XDG_CONFIG_HOME", None)], &[("HOME", Some("/u/me")), ("XDG_CONFIG_HOME", None)],
|| { || {
let paths = keydb_search_paths(); let paths = keydb_search_paths();
assert_eq!(paths.len(), 1, "just the $HOME/.config default"); assert_eq!(paths.len(), 1, "just the $HOME/.config default");
assert_eq!( assert_eq!(
paths[0], paths[0],
PathBuf::from("/home/matt") PathBuf::from("/u/me")
.join(".config") .join(".config")
.join("freemkv") .join("freemkv")
.join("keydb.cfg"), .join("keydb.cfg"),
@@ -205,15 +205,15 @@ mod tests {
fn unix_honours_xdg_config_home_first() { fn unix_honours_xdg_config_home_first() {
with_env( with_env(
&[ &[
("XDG_CONFIG_HOME", Some("/home/matt/.cfg")), ("XDG_CONFIG_HOME", Some("/u/me/.cfg")),
("HOME", Some("/home/matt")), ("HOME", Some("/u/me")),
], ],
|| { || {
let paths = keydb_search_paths(); let paths = keydb_search_paths();
assert_eq!(paths.len(), 2, "XDG dir + $HOME/.config fallback"); assert_eq!(paths.len(), 2, "XDG dir + $HOME/.config fallback");
assert_eq!( assert_eq!(
paths[0], paths[0],
PathBuf::from("/home/matt/.cfg") PathBuf::from("/u/me/.cfg")
.join("freemkv") .join("freemkv")
.join("keydb.cfg"), .join("keydb.cfg"),
"XDG_CONFIG_HOME, when set, is searched before ~/.config" "XDG_CONFIG_HOME, when set, is searched before ~/.config"