Skip to content

Commit

Permalink
Try using the supplied home var
Browse files Browse the repository at this point in the history
  • Loading branch information
ktdlr committed Oct 28, 2024
1 parent 67822b0 commit eba452f
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions packages/ciphernode/config/src/app_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,18 @@ mod tests {
#[test]
fn test_ensure_relative_path() {
Jail::expect_with(|jail| {
jail.set_env("HOME", "/home/testuser");
let home = std::env::var("HOME").unwrap_or_else(|_| "/home/testuser".to_string());
jail.set_env("HOME", &home);

let config = AppConfig {
config_file: "/home/testuser/docs/myconfig.yaml".into(),
config_file: format!("{}/docs/myconfig.yaml", &home).into(),
config_dir: "../foo".into(),
data_dir: "../bar".into(),
..AppConfig::default()
};

assert_eq!(config.key_file(), PathBuf::from("/home/testuser/foo/key"));
assert_eq!(config.db_file(), PathBuf::from("/home/testuser/bar/db"));
assert_eq!(config.key_file(), PathBuf::from(format!("{}/foo/key",home)));
assert_eq!(config.db_file(), PathBuf::from(format!("{}/bar/db", home)));

Ok(())
});
Expand All @@ -212,28 +213,29 @@ mod tests {
#[test]
fn test_defaults() {
Jail::expect_with(|jail| {
jail.set_env("HOME", "/home/testuser");
let home = std::env::var("HOME").unwrap_or_else(|_| "/home/testuser".to_string());
jail.set_env("HOME", &home);

let config = AppConfig::default();

assert_eq!(
config.key_file(),
PathBuf::from("/home/testuser/.config/enclave/key")
PathBuf::from(format!("{}/.config/enclave/key",home))
);

assert_eq!(
config.db_file(),
PathBuf::from("/home/testuser/.local/share/enclave/db")
PathBuf::from(format!("{}/.local/share/enclave/db", home))
);

assert_eq!(
config.config_file(),
PathBuf::from("/home/testuser/.config/enclave/config.yaml")
PathBuf::from(format!("{}/.config/enclave/config.yaml",home))
);

assert_eq!(
config.config_dir(),
PathBuf::from("/home/testuser/.config/enclave/")
PathBuf::from(format!("{}/.config/enclave/", home))
);

Ok(())
Expand All @@ -244,11 +246,11 @@ mod tests {
fn test_config() {
Jail::expect_with(|jail| {
let home = format!("{}", jail.directory().to_string_lossy());
jail.set_env("HOME", &home);

let filename = format!("{}/.config/enclave/config.yaml", home);
let filedir = format!("{}/.config/enclave", home);

jail.create_dir(filedir)?;
jail.set_env("HOME", &home);
jail.create_file(
filename,
r#"
Expand Down

0 comments on commit eba452f

Please sign in to comment.