Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions modules/shell/tests/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,6 @@ fn an_empty_folder_under_the_new_name_gives_way() {
assert_eq!(now(&here).sessions, mine, "the folder the user named is kept");
}

#[test]
fn a_model_written_from_home_is_named_where_it_went() {
let root = tempfile::tempdir().unwrap();
let home = dirs::home_dir().unwrap();
// Summit's data folder under the home, as the user wrote it: `~/…`.
let data = tempfile::tempdir_in(&home).unwrap();
let here = Places {
config: root.path().join("config"),
data: data.path().to_path_buf(),
documents: root.path().join("Documents"),
};
write(&here.data.join("summit/models/a.bin"), "a model");
let written = format!("~/{}/summit/models/a.bin", data.path().strip_prefix(&home).unwrap().display());
write(&here.config.join("summit/settings.toml"), &format!("model = '{written}'\n"));

let carried = carry_over(&here).unwrap();

assert!(carried.model_named, "{carried:?}");
assert_eq!(now(&here).model, here.data.join("kitokey/models/a.bin"));
}

#[test]
fn a_model_beside_summits_folder_is_not_renamed_by_its_text() {
let root = tempfile::tempdir().unwrap();
Expand Down
49 changes: 49 additions & 0 deletions modules/shell/tests/migrate_home.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! A model written from the home, `~/…`, in Summit's settings: carried over, it is named where it
//! went. Its own test binary: it points the home at a folder of its own, and the environment is the
//! process's — every test of `migrate.rs` reads the home, side by side with the others.

use std::fs;
use std::path::Path;

use kitokey_shell::migrate::{Places, carry_over};
use kitokey_shell::settings;

fn write(path: &Path, text: &str) {
fs::create_dir_all(path.parent().unwrap()).unwrap();
fs::write(path, text).unwrap();
}

#[test]
fn a_model_written_from_home_is_named_where_it_went() {
// No test reads or writes the person's home: it is a folder of the test's own.
let home = tempfile::tempdir().unwrap();
// SAFETY: the only test of this binary, and nothing else runs in it.
unsafe {
std::env::set_var("HOME", home.path());
for xdg in ["XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "XDG_STATE_HOME"] {
std::env::set_var(xdg, home.path().join(xdg));
}
}
assert_eq!(dirs::home_dir().as_deref(), Some(home.path()));
let root = tempfile::tempdir().unwrap();
// Summit's data folder under the home, as the user wrote it: `~/…`.
let data = home.path().join(".local/share");
let here = Places {
config: root.path().join("config"),
data: data.clone(),
documents: root.path().join("Documents"),
};
write(&here.data.join("summit/models/a.bin"), "a model");
write(
&here.config.join("summit/settings.toml"),
"model = '~/.local/share/summit/models/a.bin'\n",
);

let carried = carry_over(&here).unwrap();

assert!(carried.model_named, "{carried:?}");
assert_eq!(
settings::read(&here.config.join("kitokey/settings.toml")).unwrap().model,
here.data.join("kitokey/models/a.bin")
);
}
Loading