Skip to content

Commit

Permalink
fix: Fixed bug where setting token was failing on first run (#62)
Browse files Browse the repository at this point in the history
* Fixed bug where setting token was failing
* Added unit test for new behavior
  • Loading branch information
asasine authored Nov 26, 2024
1 parent 7edf050 commit 6d2d273
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/infrastructure/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,28 @@ impl Configuration {

fn write_to_file(self) -> Result<(), ConfigurationError> {
let toml_string = toml::to_string(&self)?;
std::fs::write(
Self::get_project_directories().config_dir().join(".config"),
toml_string,
)?;
let project_dirs = Self::get_project_directories();
let config_dir = project_dirs.config_dir();
std::fs::create_dir_all(config_dir)?;
std::fs::write(config_dir.join(".config"), toml_string)?;
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

/// The default configuration should be writable when the project dir doesn't exist yet.
#[test]
fn write_default_configuration_before_project_dir_exists() {
let project_dirs = Configuration::get_project_directories();
let config_dir = project_dirs.config_dir();
std::fs::remove_dir_all(config_dir).ok();
assert!(!config_dir.exists()); // sanity check

let result = Configuration::default().write_to_file();
assert!(result.is_ok());
assert!(config_dir.exists());
}
}

0 comments on commit 6d2d273

Please sign in to comment.