tests: tidy up config, forgejo and git tests
All checks were successful
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Rust / build (push) Successful in 1m13s
All checks were successful
ci/woodpecker/cron/cron-docker-builder Pipeline was successful
ci/woodpecker/cron/push-next Pipeline was successful
ci/woodpecker/cron/tag-created Pipeline was successful
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Rust / build (push) Successful in 1m13s
Coverage for config, forge, forgejo and github is now 100%.
This commit is contained in:
parent
ea9a858f48
commit
271f4ec1dc
5 changed files with 46 additions and 19 deletions
|
@ -23,10 +23,6 @@ impl WebhookMessage {
|
|||
pub const fn body(&self) -> &Body {
|
||||
&self.body
|
||||
}
|
||||
#[deprecated]
|
||||
pub const fn authorisation(&self) -> &config::WebhookAuth {
|
||||
todo!()
|
||||
}
|
||||
pub fn header(&self, header: &str) -> Option<String> {
|
||||
self.headers.get(header).map(|value| value.to_string())
|
||||
}
|
||||
|
|
|
@ -70,8 +70,7 @@ impl git::ForgeLike for ForgeJo {
|
|||
);
|
||||
let result = self.net.get::<CombinedStatus>(request).await;
|
||||
match result {
|
||||
Ok(response) => {
|
||||
match response.response_body() {
|
||||
Ok(response) => match response.response_body() {
|
||||
Some(status) => match status.state {
|
||||
ForgejoState::Success => Status::Pass,
|
||||
ForgejoState::Pending => Status::Pending,
|
||||
|
@ -80,11 +79,11 @@ impl git::ForgeLike for ForgeJo {
|
|||
ForgejoState::Blank => Status::Pending,
|
||||
},
|
||||
None => {
|
||||
warn!("No status found for commit");
|
||||
Status::Pending // assume issue is transient and allow retry
|
||||
}
|
||||
}
|
||||
#[cfg(not(tarpaulin_include))]
|
||||
unreachable!(); // response.response_body() is always Some when
|
||||
// request responseType::Json
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
warn!(?e, "Failed to get commit status");
|
||||
Status::Pending // assume issue is transient and allow retry
|
||||
|
|
|
@ -276,6 +276,33 @@ mod forgejo {
|
|||
|
||||
let_assert!(Ok(_) = forge.unregister_webhook(&webhook_id).await);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn should_return_error_on_network_error() {
|
||||
let repo_details = given::repo_details();
|
||||
let hostname = repo_details.forge.hostname();
|
||||
let repo_path = &repo_details.repo_path;
|
||||
use secrecy::ExposeSecret;
|
||||
let token = repo_details.forge.token().expose_secret();
|
||||
let webhook_id = given::a_webhook_id();
|
||||
let mut net = given::a_network();
|
||||
|
||||
net.add_delete_error(
|
||||
format!(
|
||||
"https://{hostname}/api/v1/repos/{repo_path}/hooks/{webhook_id}?token={token}"
|
||||
)
|
||||
.as_str(),
|
||||
"error",
|
||||
);
|
||||
|
||||
let forge = given::a_forgejo_forge(&repo_details, net);
|
||||
|
||||
let_assert!(Err(err) = forge.unregister_webhook(&webhook_id).await);
|
||||
assert!(
|
||||
matches!(err, git::forge::webhook::Error::FailedToUnregister(_)),
|
||||
"{err:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
mod register_webhook {
|
||||
|
|
|
@ -28,7 +28,9 @@ pub async fn unregister(
|
|||
let result = net.delete(request).await;
|
||||
if let Err(e) = result {
|
||||
tracing::warn!("Failed to unregister webhook");
|
||||
return Err(git::forge::webhook::Error::FailedToRegister(e.to_string()));
|
||||
return Err(git::forge::webhook::Error::FailedToUnregister(
|
||||
e.to_string(),
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ pub enum Error {
|
|||
#[error("failed to register: {0}")]
|
||||
FailedToRegister(String),
|
||||
|
||||
#[error("failed to unregister: {0}")]
|
||||
FailedToUnregister(String),
|
||||
|
||||
#[error("network response was empty")]
|
||||
NetworkResponseEmpty,
|
||||
|
||||
|
|
Loading…
Reference in a new issue