From c6a29fdbd84507b7b2fba55dbf602ef7e4bdf8c9 Mon Sep 17 00:00:00 2001 From: Mike Stemle Date: Thu, 22 Feb 2024 02:19:20 -0500 Subject: [PATCH] Adding test for actions().actions_delete_workflow_run_logs_test() (#584) --- .../actions_delete_workflow_run_logs_test.rs | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/actions_delete_workflow_run_logs_test.rs diff --git a/tests/actions_delete_workflow_run_logs_test.rs b/tests/actions_delete_workflow_run_logs_test.rs new file mode 100644 index 00000000..5187ae10 --- /dev/null +++ b/tests/actions_delete_workflow_run_logs_test.rs @@ -0,0 +1,77 @@ +mod mock_error; + +use mock_error::setup_error_handler; +use octocrab::Octocrab; +use wiremock::{ + matchers::{method, path}, + Mock, MockServer, ResponseTemplate, +}; + +async fn setup_delete_workflow_run_logs_api(template: ResponseTemplate) -> MockServer { + let owner: &str = "org"; + let repo: &str = "some-repo"; + let run_id: u64 = 456; + + let mock_server = MockServer::start().await; + + Mock::given(method("DELETE")) + .and(path(format!( + "/repos/{owner}/{repo}/actions/runs/{run_id}/logs" + ))) + .respond_with(template.clone()) + .mount(&mock_server) + .await; + + setup_error_handler( + &mock_server, + &format!("DELETE on /repos/{owner}/{repo}/actions/runs/{run_id}/logs was not received"), + ) + .await; + mock_server +} + +fn setup_octocrab(uri: &str) -> Octocrab { + Octocrab::builder().base_uri(uri).unwrap().build().unwrap() +} + +const OWNER: &str = "org"; +const REPO: &str = "some-repo"; +const RUN_ID: u64 = 456; + +#[tokio::test] +async fn should_delete_workflow_run_logs_204() { + let template = ResponseTemplate::new(204); + let mock_server = setup_delete_workflow_run_logs_api(template).await; + let client = setup_octocrab(&mock_server.uri()); + + let actions = client.actions(); + + let result = actions + .delete_workflow_run_logs(&OWNER.to_owned(), &REPO.to_owned(), RUN_ID.into()) + .await; + + assert!( + result.is_ok(), + "expected successful result, got error: {:#?}", + result + ); +} + +#[tokio::test] +async fn should_delete_workflow_run_logs_500() { + let template = ResponseTemplate::new(500); + let mock_server = setup_delete_workflow_run_logs_api(template).await; + let client = setup_octocrab(&mock_server.uri()); + + let actions = client.actions(); + + let result = actions + .delete_workflow_run_logs(&OWNER.to_owned(), &REPO.to_owned(), RUN_ID.into()) + .await; + + assert!( + result.is_err(), + "expected error result, got success somehow: {:#?}", + result + ); +}