test: editor crashes while in 'pueue edit'
@@ -2,6 +2,7 @@ use std::collections::HashMap;
use anyhow::{Context, Result};
use pueue_lib::network::message::Message;
+use pueue_lib::task::TaskStatus;
use crate::fixtures::*;
use crate::helper::*;
@@ -37,3 +38,35 @@ async fn edit_task() -> Result<()> {
Ok(())
}
+
+/// Test that automatic restoration of a task's state works, if the edit command fails for some
+/// reason.
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn fail_to_edit_task() -> Result<()> {
+ let daemon = daemon().await?;
+ let shared = &daemon.settings.shared;
+
+ // Create a stashed message which we'll edit later on.
+ let mut message = create_add_message(shared, "this is a test");
+ message.stashed = true;
+ send_message(shared, Message::Add(message))
+ .await
+ .context("Failed to to add task to group.")?;
+
+ // Run a editor command that crashes.
+ let mut envs = HashMap::new();
+ envs.insert("EDITOR", "non_existing_test_binary");
+ let command = run_client_command_with_env(shared, &["edit", "0"], envs).await;
+ assert!(
+ command.is_err(),
+ "The command should fail, as the command isn't valid"
+ );
+
+ // Make sure that nothing has changed and the task is `Stashed` again.
+ let state = get_state(shared).await?;
+ let task = state.tasks.get(&0).unwrap();
+ assert_eq!(task.command, "this is a test");
+ assert_eq!(task.status, TaskStatus::Stashed { enqueue_at: None });
+
+ Ok(())
+}
