tests Client 'status --json'
+use anyhow::Context;
use anyhow::Result;
+use pueue_lib::state::State;
use rstest::rstest;
use crate::fixtures::*;
@@ -73,3 +75,28 @@ async fn colored_status() -> Result<()> {
Ok(())
}
+
+/// Calling `pueue status --json` will result in the current state being printed to the cli.
+#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
+async fn status_json() -> Result<()> {
+ let daemon = daemon().await?;
+ let shared = &daemon.settings.shared;
+
+ // Add a task and wait until it finishes.
+ assert_success(add_task(shared, "ls", false).await?);
+ wait_for_task_condition(shared, 0, |task| task.is_done()).await?;
+
+ let output = run_client_command(shared, &["status", "--json"]).await?;
+
+ let json = String::from_utf8_lossy(&output.stdout);
+ let deserialized_state: State =
+ serde_json::from_str(&*json).context("Failed to deserialize json state")?;
+
+ let state = get_state(shared).await?;
+ assert_eq!(
+ deserialized_state, *state,
+ "Json state differs from actual daemon state."
+ );
+
+ Ok(())
+}
