From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id D6A571FF15E for ; Mon, 29 Sep 2025 11:52:54 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id AA61EE424; Mon, 29 Sep 2025 11:53:00 +0200 (CEST) From: Filip Schauer To: pbs-devel@lists.proxmox.com Date: Mon, 29 Sep 2025 11:52:32 +0200 Message-ID: <20250929095236.38251-3-f.schauer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20250929095236.38251-1-f.schauer@proxmox.com> References: <20250929095236.38251-1-f.schauer@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1759139558175 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.007 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox v3 2/2] rest-server: add tests for upid_read_status X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Backup Server development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pbs-devel-bounces@lists.proxmox.com Sender: "pbs-devel" Test that the task state is correctly extracted from a task log. Signed-off-by: Filip Schauer --- proxmox-rest-server/tests/worker_task.rs | 65 ++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 proxmox-rest-server/tests/worker_task.rs diff --git a/proxmox-rest-server/tests/worker_task.rs b/proxmox-rest-server/tests/worker_task.rs new file mode 100644 index 00000000..c2afc463 --- /dev/null +++ b/proxmox-rest-server/tests/worker_task.rs @@ -0,0 +1,65 @@ +use std::fs::{remove_dir_all, write}; + +use proxmox_rest_server::{ + init_worker_tasks, upid_log_path, upid_read_status, TaskState, WorkerTask, +}; +use proxmox_sys::fs::{make_tmp_dir, CreateOptions}; + +fn upid_read_status_test_helper(log: &str, expected: &TaskState) { + let task = WorkerTask::new("x", None, "u@pam".into(), false).unwrap().0; + let upid = task.upid(); + let logfile = upid_log_path(upid).unwrap(); + write(logfile, log).unwrap(); + + let status = upid_read_status(upid).unwrap(); + + assert!(&status == expected); +} + +#[tokio::test] +async fn test_upid_read_status() { + let tmpdir = make_tmp_dir("/tmp/", None).unwrap(); + init_worker_tasks(tmpdir.clone(), CreateOptions::new()).unwrap(); + + upid_read_status_test_helper( + "2025-09-22T14:31:04+02:00: The quick, brown fox jumps over a lazy dog.\n\ + 2025-09-22T14:31:04+02:00: TASK ERROR: Something went wrong", + &TaskState::Error { + message: "Something went wrong".into(), + endtime: 1758544264, + }, + ); + + upid_read_status_test_helper( + "1970-01-01T01:00:00+01:00: The quick, brown fox jumps over a lazy dog.\n\ + 1970-01-01T01:00:01+01:00: TASK ERROR: Lorem ipsum dolor sit amet\n\ + consetetur sadipscing elitr sed diam nonumy eirmod tempor invidunt\n\ + ut labore et dolore magna aliquyam erat, sed diam voluptua.", + &TaskState::Error { + message: "Lorem ipsum dolor sit amet".into(), + endtime: 1, + }, + ); + + upid_read_status_test_helper( + "2025-09-24T10:56:12+02:00: Lorem ipsum dolor sit amet\n\ + 2025-09-24T10:56:13+02:00: consetetur sadipscing elitr\n\ + 2025-09-24T10:56:14+02:00: TASK OK", + &TaskState::OK { + endtime: 1758704174, + }, + ); + + upid_read_status_test_helper( + "2025-09-23T12:07:49+02:00: Warning 1\n\ + 2025-09-23T12:29:11+02:00: Warning 2\n\ + 2025-09-23T12:29:11+02:00: TASK WARNINGS: 2", + &TaskState::Warning { + count: 2, + endtime: 1758623351, + }, + ); + + // Cleanup + remove_dir_all(tmpdir).unwrap(); +} -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel