Test cli behavior

This commit is contained in:
Mubelotix
2025-07-30 15:44:42 +02:00
parent 3e77c1d8c8
commit b565ec1497
2 changed files with 25 additions and 1 deletions

View File

@ -182,6 +182,10 @@ impl Server<Owned> {
self.service.patch("/network", value).await
}
pub async fn set_webhooks(&self, value: Value) -> (Value, StatusCode) {
self.service.patch("/webhooks", value).await
}
pub async fn get_metrics(&self) -> (Value, StatusCode) {
self.service.get("/metrics").await
}
@ -447,6 +451,10 @@ impl<State> Server<State> {
pub async fn get_network(&self) -> (Value, StatusCode) {
self.service.get("/network").await
}
pub async fn get_webhooks(&self) -> (Value, StatusCode) {
self.service.get("/webhooks").await
}
}
pub fn default_settings(dir: impl AsRef<Path>) -> Opt {

View File

@ -68,12 +68,13 @@ async fn create_webhook_server() -> WebhookHandle {
}
#[actix_web::test]
async fn test_basic_webhook() {
async fn test_cli_webhook() {
let WebhookHandle { server_handle, url, mut receiver } = create_webhook_server().await;
let db_path = tempfile::tempdir().unwrap();
let server = Server::new_with_options(Opt {
task_webhook_url: Some(Url::parse(&url).unwrap()),
task_webhook_authorization_header: Some(String::from("Bearer a-secret-token")),
..default_settings(db_path.path())
})
.await
@ -125,5 +126,20 @@ async fn test_basic_webhook() {
assert!(nb_tasks == 5, "We should have received the 5 tasks but only received {nb_tasks}");
let (webhooks, code) = server.get_webhooks().await;
snapshot!(code, @"200 OK");
snapshot!(webhooks, @r#"
{
"webhooks": {
"_cli": {
"url": "http://127.0.0.1:51503/",
"headers": {
"Authorization": "Bearer a-secret-token"
}
}
}
}
"#);
server_handle.abort();
}