Skip to content

Commit

Permalink
Added tests to prove repos().secrets().delete_secret() (#570)
Browse files Browse the repository at this point in the history
- Added test for 204 case
- Added test for 500 case
  • Loading branch information
manchicken authored Feb 9, 2024
1 parent eca3741 commit ff27745
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/repo_secrets_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ async fn setup_put_api(template: ResponseTemplate, secrets_path: &str) -> MockSe
mock_server
}

async fn setup_delete_api(template: ResponseTemplate, secrets_path: &str) -> MockServer {
let mock_server = MockServer::start().await;

Mock::given(method("DELETE"))
.and(path(format!(
"/repos/{OWNER}/{REPO}/actions/secrets{secrets_path}"
)))
.respond_with(template)
.mount(&mock_server)
.await;
setup_error_handler(
&mock_server,
&format!("DELETE on /repos/{OWNER}/{REPO}/actions/secrets{secrets_path} was not received"),
)
.await;
mock_server
}

fn setup_octocrab(uri: &str) -> Octocrab {
Octocrab::builder().base_uri(uri).unwrap().build().unwrap()
}
Expand Down Expand Up @@ -187,3 +205,37 @@ async fn should_add_secret() {
let item = result.unwrap();
assert_eq!(item, CreateRepositorySecretResponse::Created);
}

#[tokio::test]
async fn should_delete_secret() {
let template = ResponseTemplate::new(204);
let mock_server = setup_delete_api(template, "/GH_TOKEN").await;
let result = setup_octocrab(&mock_server.uri())
.repos(OWNER.to_owned(), REPO.to_owned())
.secrets()
.delete_secret("GH_TOKEN")
.await;

assert!(
result.is_ok(),
"expected successful result, got error: {:#?}",
result
);
}

#[tokio::test]
async fn should_noop_secret_500() {
let template = ResponseTemplate::new(500);
let mock_server = setup_delete_api(template, "/GH_TOKEN").await;
let result = setup_octocrab(&mock_server.uri())
.repos(OWNER.to_owned(), REPO.to_owned())
.secrets()
.delete_secret("GH_TOKEN")
.await;

assert!(
result.is_err(),
"expected error result, got success somehow: {:#?}",
result
);
}

0 comments on commit ff27745

Please sign in to comment.