Skip to content

Commit

Permalink
Merge pull request #481 from Nukesor/fix-pueue-aliases-default-location
Browse files Browse the repository at this point in the history
fix: Default config location of pueue_aliases.yml
  • Loading branch information
Nukesor authored Nov 28, 2023
2 parents 4a77981 + 6dde953 commit 3640183
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 38 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed

- Fixed panic when calling parallel without arguments [#477](https://github.com/Nukesor/pueue/issues/477)
- Fix typo
- Fixed wrong default location for `pueue_aliases.yml` [#480](https://github.com/Nukesor/pueue/issues/480)
- Fix typos

## [3.3.1] - 2023-10-27

Expand Down
73 changes: 39 additions & 34 deletions pueue/tests/client/integration/follow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,39 +102,44 @@ async fn fail_on_non_existing(#[case] read_local_logs: bool) -> Result<()> {
Ok(())
}

/// Fail and print an error message when following a non-existing task disappears
/// This test is ignored on apple, since it's super flaky. Somebody has to debug this.
#[cfg(not(target = "x86_64-apple-darwin"))]
#[rstest]
#[case(true)]
#[case(false)]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn fail_on_disappearing(#[case] read_local_logs: bool) -> Result<()> {
let mut daemon = daemon().await?;
set_read_local_logs(&mut daemon, read_local_logs)?;
let shared = &daemon.settings.shared;

// Add a task echoes something and waits for a while
assert_success(add_task(shared, "echo test && sleep 20").await?);
wait_for_task_condition(shared, 0, |task| task.is_running()).await?;

// Reset the daemon after 2 seconds. At this point, the client will already be following the
// output and should notice that the task went away..
// This is a bit hacky, but our client test helper always waits for the command to finish
// and I'm feeling too lazy to add a new helper function now.
let moved_shared = shared.clone();
tokio::task::spawn(async move {
sleep_ms(2000).await;
// Reset the daemon
send_message(&moved_shared, ResetMessage {})
.await
.expect("Failed to send Start tasks message");
});

// Execute `follow` and remove the task
// The client should exit with exit code `1`.
let output = run_client_command(shared, &["follow", "0"])?;

assert_snapshot_matches_stdout("follow__fail_on_disappearing", output.stdout)?;

Ok(())
mod non_apple {
use super::*;

/// Fail and print an error message when following a non-existing task disappears
#[rstest]
#[case(true)]
#[case(false)]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn fail_on_disappearing(#[case] read_local_logs: bool) -> Result<()> {
let mut daemon = daemon().await?;
set_read_local_logs(&mut daemon, read_local_logs)?;
let shared = &daemon.settings.shared;

// Add a task echoes something and waits for a while
assert_success(add_task(shared, "echo test && sleep 20").await?);
wait_for_task_condition(shared, 0, |task| task.is_running()).await?;

// Reset the daemon after 2 seconds. At this point, the client will already be following the
// output and should notice that the task went away..
// This is a bit hacky, but our client test helper always waits for the command to finish
// and I'm feeling too lazy to add a new helper function now.
let moved_shared = shared.clone();
tokio::task::spawn(async move {
sleep_ms(2000).await;
// Reset the daemon
send_message(&moved_shared, ResetMessage {})
.await
.expect("Failed to send Start tasks message");
});

// Execute `follow` and remove the task
// The client should exit with exit code `1`.
let output = run_client_command(shared, &["follow", "0"])?;

assert_snapshot_matches_stdout("follow__fail_on_disappearing", output.stdout)?;

Ok(())
}
}
10 changes: 7 additions & 3 deletions pueue_lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,15 @@ pub struct NestedSettings {
pub shared: Shared,
}

pub fn default_configuration_directory() -> Option<PathBuf> {
dirs::config_dir().map(|dir| dir.join("pueue"))
}

/// Get the default config directory.
/// If no config can be found, fallback to the current directory.
pub fn configuration_directories() -> Vec<PathBuf> {
if let Some(config_dir) = dirs::config_dir() {
vec![config_dir.join("pueue"), PathBuf::from(".")]
if let Some(config_dir) = default_configuration_directory() {
vec![config_dir, PathBuf::from(".")]
} else {
vec![PathBuf::from(".")]
}
Expand Down Expand Up @@ -269,7 +273,7 @@ impl Shared {
pub fn alias_file(&self) -> PathBuf {
if let Some(path) = &self.alias_file {
expand_home(path)
} else if let Some(config_dir) = dirs::config_dir() {
} else if let Some(config_dir) = default_configuration_directory() {
config_dir.join("pueue_aliases.yml")
} else {
PathBuf::from("pueue_aliases.yml")
Expand Down

0 comments on commit 3640183

Please sign in to comment.